user@user:~/langs/c$ cat 3264int.c
#include <stdio.h>
int main(){
long z;
printf("Long int size is %d bytes long!\n", sizeof(z));
return 0;
}
user@user:~/langs/c$ cat 3264int.c ^C
user@user:~/langs/c$ gcc -m32 -o 32int 3264int.c
user@user:~/langs/c$ gcc -m64 -o 64int 3264int.c
3264int.c: In function ‘main’:
3264int.c:4: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long unsigned int’ cat 3264int.c
Run Code Online (Sandbox Code Playgroud)
我尝试将类型更改为zint,但仍然无法编译.
这是一个警告,而不是错误.你有一个结果可执行文件.但是,如果你想用编译-pedantic或-Werror则不会.如果您正在使用此微观示例,那么您需要做的是将格式说明符更改为%ld.在你的平台size_t是什么sizeof就回去了,大概是在64位的8个字节,但在32位4个字节.%d可以显示32位整数,但不能显示64位整数.