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
I tried changing the type for z to int, and it still fails to compile.
That’s a warning, not an error. You got a resulting executable. However, if you’re trying to compile with
-pedanticor-Werrorthen you won’t. If this microexample is what you’re working with however, then what you need to do is change your format specifier to%ld. On your platformsize_twhich is whatsizeofwill return, is probably 8 bytes on 64-bit, but 4 bytes on 32-bit.%dcan display a 32-bit integer, but not a 64-bit integer.