如何使用GCC打印ff long long int
和unsigned long long int
C99?
我搜索了其他建议使用的帖子,%lld
但它给出了这些警告:
警告#1:格式为[-Wformat] |的未知转换类型字符'l'
警告#2:格式参数太多[-Wformat-extra-args] |
对于以下尝试:
#include <stdio.h>
int main()
{
long long int x = 0;
unsigned long long int y = 0;
printf("%lld\n", x);
printf("%llu\n", y);
}
Run Code Online (Sandbox Code Playgroud)
nos*_*nos 63
如果你在windows上并使用mingw,gcc使用win32运行时,其中printf需要%I64d
64位整数.(%I64u
对于未经编码的64位整数)
对于大多数其他平台,您可以%lld
长时间打印.(%llu
如果它是未签名的).这在C99中是标准化的.
gcc没有完整的C运行时,它遵循它运行的平台 - 所以一般情况下你需要查阅你的特定平台的文档 - 独立于gcc.
对于可移植代码,可以使用inttypes.h中的宏。它们扩展到适合平台的正确位置。
PRId64
例如,对于 64 位整数,可以使用宏。
int64_t n = 7;
printf("n is %" PRId64 "\n", n);
Run Code Online (Sandbox Code Playgroud)