您的printf
格式說明符與您的類型不匹配,導致未定義的行爲。嘗試:
printf("long long value %llX\n", test);
%d
是一個sizeof
結果的格式不正確了。你應該在那裏使用%zu
。
你的編譯器會警告你,如果你把一些警告設置(clang
的默認操作爲例):
example.c:6:30: warning: format specifies type 'unsigned int' but the argument
has type 'unsigned long long' [-Wformat]
printf("long long value %X\n", test);
~^ ~~~~
%llX
example.c:7:14: warning: format specifies type 'int' but the argument has type
'unsigned long' [-Wformat]
printf("%d", sizeof(test));
~^ ~~~~~~~~~~~~
%ld
2 warnings generated.
編輯:我在你的問題發現你使用Visual C. %z
是一個C99功能,可能不被編譯器支持。在這種情況下,您應該檢查文檔以查看使用的正確格式。
我相信I64是MSVC的,並不符合標準。 –
@Timothy,OP說他在使用Visual C. –