[英]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: 我正在尝试使用以下方式打印一些64位无符号整数:
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: 如果将格式设置字符串更改为%016lx,则会收到有关使用错误类型的编译警告,并且仅输出低32位:
00000000FFFFFFFF
I've got the -std=c99 string in my compiler options, which should enforce the ll option, right? 我的编译器选项中有-std = c99字符串,该字符串应强制执行ll选项,对吗?
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. 作为参考,这是随最新版本的Silicon Labs的Simplicity Studio IDE一起提供的arm-none-eabi-gcc编译器(v4.7.3)。
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 . printf或scanf的实现取决于您使用的libc,可能不支持long long 。 Please, check it by printing value of PRIx64 - I guess in your case it will be "lx" instead of "llx". 请通过打印PRIx64的值进行检查-我猜在您的情况下它将是“ lx”而不是“ llx”。
Pasting a part of inttype.h of ARM toolchain gcc-arm-embedded 粘贴ARM工具链gcc-arm-embedded的inttype.h的一部分
/* 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.