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
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.
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;
}