今早在网上偶然看到一篇文章《32位程序移植到64位平台前的准备工作》,文中介绍了32位平台的程序向64位平台进行移植需要注意的一些事项和操作建议。
自己对于64位平台上各种数据类型分别占用多少字节,存在一些疑问,所以用C/C++中的sizeof分别在这两种平台上进行了测试。
运行结果如下:(分别用蓝色和红色标记了两者的差异)
——————————————————————————
机器平台:X86_64 处理器
操作系统:Red Hat 4.1.2-14
编译器: gcc version 4.1.2 20070626
Size of char is: 1
Size of unsigned char is: 1
Size of signed char is: 1
Size of int is: 4
Size of short is: 2
Size of long is: 8
Size of long int is: 8
Size of signed int is: 4
Size of unsigned int is: 4
Size of unsigned long int is: 8
Size of long long int is: 8
Size of unsigned long long is: 8
Size of float is: 4
Size of double is: 8
Size of long double is: 16
Size of (void *) is: 8
Size of (char *) is: 8
Size of (int *) is: 8
Size of (long *) is: 8
Size of (long long *) is: 8
Size of (float *) is: 8
Size of (double *) is: 8
——————————————————————————
机器平台: X86_32 处理器
操作系统: Windows XP SP2
编译器: VS2005自带的C++编译器
Size of char is: 1
Size of unsigned char is: 1
Size of signed char is: 1
Size of int is: 4
Size of short is: 2
Size of long is: 4
Size of long int is: 4
Size of signed int is: 4
Size of unsigned int is: 4
Size of unsigned long int is: 4
Size of long long int is: 8
Size of unsigned long long is: 8
Size of float is: 4
Size of double is: 8
Size of long double is: 8
Size of (void *) is: 4
Size of (char *) is: 4
Size of (int *) is: 4
Size of (long *) is: 4
Size of (long long *) is: 4
Size of (float *) is: 4
Size of (double *) is: 4