简体   繁体   中英

GCC ARM C compiler not respecting -std=c99 for %llx printf formatting code

I'm trying to print some 64-bit unsigned integers using something like this:

uint64_t x = 0xFFFFFFFFFFFFFFFF;
printf("Value: %016llx \n", x); 

and I get this in response:

0000000000000000lx

If I change the formatting string to %016lx I get a compile warning for using the wrong type and it only prints the lower 32 bits:

00000000FFFFFFFF

I've got the -std=c99 string in my compiler options, which should enforce the ll option, right?

For reference, this is the arm-none-eabi-gcc compiler (v4.7.3) that ships with the latest version of Silicon Labs' Simplicity Studio IDE.

Have you tried this ?

#include <stdio.h>
#include <inttypes.h>

int
main(void)
{
    uint64_t n = 0x123456789;

    printf("n = %#" PRIx64 "\n", n);

    return (0);
}

Implementation of printf or scanf depends on libc your're using and may not support long long . Please, check it by printing value of PRIx64 - I guess in your case it will be "lx" instead of "llx".

Pasting a part of inttype.h of ARM toolchain gcc-arm-embedded

/* 64-bit types */
#if __have_long64
#define __PRI64(x) __STRINGIFY(l##x)
#define __SCN64(x) __STRINGIFY(l##x)
#elif __have_longlong64
#define __PRI64(x) __STRINGIFY(ll##x)
#define __SCN64(x) __STRINGIFY(ll##x)
#else
#define __PRI64(x) __STRINGIFY(x)
#define __SCN64(x) __STRINGIFY(x)
#endif
...
#define PRIx64          __PRI64(x)
#define PRIX64          __PRI64(X)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM