64-bit type support

cancel
Showing results for 
Search instead for 
Did you mean: 

64-bit type support

536 Views
mmbds
Contributor I

I'm working on the K64F freedom board trying to port some code and running into an issue when trying to work with 64-bit types. The following snippet

 

snprintf(text, idx, "%"PRId64"", val);

 

produces the following warning

 

warning: format '%d' expects argument of type 'int', but argument 4 has type 'int64_t' [-Wformat=]

 

at compile time. Digging into inttypes.h which defines PRId64 I found that it's dependant on the define __have_longlong64 to correctly set PRId64 to the expected value of lld as expected by snprintf. When I look at

 

 

I see that there are a few different versions of the stdint.h header, specifically I see the following

  1. toolchain/arm-none-eabi/include/stdint.h
  2. toolchain/lib/gcc/arm-none-eabi/4.8.4/include/stdint.h
  3. toolchain/lib/gcc/arm-none-eabi/4.8.4/include/sdtint-gcc.h

 

File #2 essentially wraps #3. They don't define __have_longlong64, even though the code completion shows that an int64_t expands to long long int. It also seems that trying to print an int64_t by manually specifying %lld doesn't work and just results ld being printed.

Labels (1)
0 Kudos
1 Reply

124 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, David,

I have used the following code based on KDS3.0, I can pass the compiling and generate the *.elf file.

#include "MKM34Z7.h"

#include "stdio.h"

#include "inttypes.h"

static int i = 0;

char sarray[50];

long long jdata;

int main(void)

{

    /* Write your code here */

    printf("std=%d", i);

    jdata=0x1234567812345678;

    snprintf(sarray,40, "stdlib=%"PRId64"",jdata);

    __asm("nop");

    /* This for loop should be replaced. By default this loop allows a single stepping. */

    for (;;) {

        __asm("nop");

    }

    /* Never leave main */

    return 0;

}

0 Kudos