1. 程式人生 > 其它 >64位Linux系統下32位程式與64位程式資料型別分析

64位Linux系統下32位程式與64位程式資料型別分析

#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)系統下編譯此程式:

  1. 編譯為64位程式
    gcc type_szie.c -o type_size_64.out
    結果如下所示:

  2. 編譯為32位程式

  • 安裝編譯32位程式所需的軟體包
    sudo apt install build-essential module-assistant gcc-multilib g++-multilib
  • 編譯
    gcc -m32 type_szie.c -o type_size_32.out
    結果如下所示:
  1. 分析
    32位的定址空間是\(2^{32}\), 即32個bit, 也就是4個位元組. 同理64位編譯器.

參考部落格:

  1. https://www.cnblogs.com/l199616j/p/10401094.html
  2. https://blog.csdn.net/longintchar/article/details/50557832