调用的代码
undefined behaviour
因为您使用了错误的printf格式说明符。
GCC编译器警告:
prog.c: In function 'main':
prog.c:5:32: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long unsigned int' [-Wformat=]
printf("unsigned char has %d bytes.\n", sizeof(unsigned char));
~^ ~~~~~~~~~~~~~~~~~~~~~
%ld
prog.c:13:15: warning: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'int' [-Wformat=]
printf("%lu\n", a - 1);
~~^ ~~~~~
%u
prog.c:14:16: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 2 has type 'int' [-Wformat=]
printf("%llu\n", a - 1);
~~~^ ~~~~~
%u
prog.c:15:15: warning: format '%zu' expects argument of type 'size_t', but argument 2 has type 'int' [-Wformat=]
printf("%zu\n", a - 1);
~~^ ~~~~~
%u
C11$7.19.6.1第9页:
[…]如果任何参数不是对应的
转换规范,行为未定义。