如何用C打印int 64_t类型C99标准具有字节大小类似int 64_t的整数类型。我使用以下代码:#include <stdio.h>#include <stdint.h>int64_t my_int = 999999999999999999;printf("This is my_int: %I64d\n", my_int);我收到了编译器的警告:warning: format ‘%I64d’ expects type ‘int’, but argument 2 has type ‘int64_t’我试过:printf("This is my_int: %lld\n", my_int); // long long decimal但我也收到同样的警告。我正在使用这个编译器:~/dev/c$ cc -vUsing built-in specs.Target: i686-apple-darwin10Configured with: /var/tmp/gcc/gcc-5664~89/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5664)在没有警告的情况下,我应该使用哪种格式打印我的INT变量?
3 回答
慕哥9229398
TA贡献1877条经验 获得超6个赞
%j
int64_t
uint64_t
:
#include <stdio.h>#include <stdint.h>int main(int argc, char *argv[]){ int64_t a = 1LL << 63; uint64_t b = 1ULL << 63; printf("a=%jd (0x%jx)\n", a, a); printf("b=%ju (0x%jx)\n", b, b); return 0;}
gcc -Wall -pedantic -std=c99
a=-9223372036854775808 (0x8000000000000000)b=9223372036854775808 (0x8000000000000000)
printf(3)
j
intmax_t
uintmax_t
int64_t
intmax_t
uint64_t
- 3 回答
- 0 关注
- 4046 浏览
添加回答
举报
0/150
提交
取消