在32位与64位系统比较C++主要类型的长度
1、源代码
#include
using namespace std;
int main(int argc, const char * argv[])
{
cout << "sizeof(char) = " << sizeof(char) << endl;
cout << "sizeof(short) = " << sizeof(short) << endl;
cout << "sizeof(int) = " << sizeof(int) << endl;
cout << "sizeof(float) = " << sizeof(float) << endl;
cout << "sizeof(long) = " << sizeof(long) << endl;
cout << "sizeof(void *) = " << sizeof(void *) << endl;
cout << "sizeof(long long) = " << sizeof(long long) << endl;
cout << "sizeof(double) = " << sizeof(double) << endl;
return 0;
}
2、32位系统
macos系统(版本号:10.13.2)
编译器:clang++
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.3.0)
编译选项:-arch i386
sizeof(char) = 1
sizeof(short) = 2
sizeof(int) = 4
sizeof(float) = 4
sizeof(long) = 4
sizeof(void *) = 4
sizeof(long long) = 8
sizeof(double) = 8
3、64位系统
macos系统(版本号:10.13.2)
编译器:clang++
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.3.0)
编译选项:-arch x86_64
sizeof(char) = 1
sizeof(short) = 2
sizeof(int) = 4
sizeof(float) = 4
sizeof(long) = 8
sizeof(void *) = 8
sizeof(long long) = 8
sizeof(double) = 8
4、长度对比表
32位系统与64位系统主要类型长度对比表
类型 |
32位系统长度 |
64位系统长度 |
说明 |
char |
1 |
1 |
|
short |
2 |
2 |
|
int |
4 |
4 |
|
float |
4 |
4 |
|
long |
4 |
8 |
long类型:32位系统4字节,64位系统8字节 |
void * |
4 |
8 |
指针类型:32位系统4字节,64位系统8字节 |
long long |
8 |
8 |
|
double |
8 |
8 |
|