sizeof在不同平台的值并不一样,大家注意下:
/* Ubuntu12_x64环境下: sizeof()返回值类型是long unsigned int sizeof(long) = 8 sizeof(void) = 1 sizeof(void*) = 8 Win7_x64, VC2010环境下(目标机器: 32位): sizeof(long) = 4 sizeof(void) = 0 sizeof(void*) = 4 Win7_x64, VC2010环境下(目标机器: 64位): sizeof(long) = 4 sizeof(void) = 0 sizeof(void*) = 8 */ #include <string.h> #include <stdio.h> int main() { printf("%d\n", sizeof(int)); // 4 printf("%lu\n", sizeof(long)); printf("%lu\n", sizeof(float)); // 4 printf("%lu\n", sizeof(double)); // 8 printf("%lu\n", sizeof(long long)); // 8 printf("%lu\n", sizeof(void)); printf("%lu\n", sizeof(void*)); return 0; }