64位Linux系統下32位程式與64位程式資料型別分析
阿新 • • 發佈:2021-10-08
#include <stdio.h> int main() { printf("the size of 'char': %d Byte\n", sizeof(char)); printf("the size of 'short int': %d Byte\n", sizeof(short int)); printf("the size of 'int': %d Byte\n", sizeof(int)); printf("the size of 'unsigned int': %d Byte\n", sizeof(unsigned int)); printf("the size of 'float': %d Byte\n", sizeof(float)); printf("the size of 'double': %d Byte\n", sizeof(double)); printf("the size of 'long': %d Byte\n", sizeof(long)); printf("the size of 'long long': %d Byte\n", sizeof(long long)); printf("the size of 'unsigned long': %d Byte\n", sizeof(unsigned long)); printf("the size of 'void*': %d Byte\n", sizeof(void*)); return 0; }
在64位Linux(Debian)系統下編譯此程式:
-
編譯為64位程式
gcc type_szie.c -o type_size_64.out
結果如下所示:
-
編譯為32位程式
- 安裝編譯32位程式所需的軟體包
sudo apt install build-essential module-assistant gcc-multilib g++-multilib
- 編譯
gcc -m32 type_szie.c -o type_size_32.out
結果如下所示:
- 分析
32位的定址空間是\(2^{32}\), 即32個bit, 也就是4個位元組. 同理64位編譯器.
參考部落格: