为什么在 Turbo C 编译器中 sizeof(int) 是 2 个字节而在 gcc Linux 编译器中是 4 个字节?
Why in Turbo C compiler sizeof(int) is 2 bytes and in gcc Linux compiler is 4 byte?
为什么在 Turbo C 编译器中 sizeof(int)
是 2 个字节,而在 gcc 中 Linux 编译器是 4 个字节?
sizeof(int)
并非在所有平台上都是常量。
因系统而异。
PS: 只有 sizeof 对象在所有平台上都是不变的 sizeof(char)
sizeof(int)
因机器而异(有时因编译器而异)。
通常sizeof(int)
表示CPU的"natural"字宽。但是如果你的编译器在 x64 机器上作为 x86 程序运行,即使这个假设也会被打破。
在MSDOS中的指令代码是16 bit | 2 Bytes
。
因此,最大整数值为 16bit
个整数。
到目前为止我分析的内容:
The keyword int
differs from compiler to compiler.
Turbo C is a 16 bit
compiler so it compiles the code into a 16 bit
machine code for the processor!
As we all know, a compiler will convert the code to a machine code in order to work.
Same applies for GCC.
我们今天使用的计算机是 32/64
位。
编译器应该支持使任何应用程序正常工作的体系结构。
- GCC 是
32/64 bit
编译器。所以,sizeof(int)
是 4 Bytes
.
- Turbo C 是
16bit
编译器。所以,sizeof(int)
是 2 Bytes
.
为什么在 Turbo C 编译器中 sizeof(int)
是 2 个字节,而在 gcc 中 Linux 编译器是 4 个字节?
sizeof(int)
并非在所有平台上都是常量。
因系统而异。
PS: 只有 sizeof 对象在所有平台上都是不变的 sizeof(char)
sizeof(int)
因机器而异(有时因编译器而异)。
通常sizeof(int)
表示CPU的"natural"字宽。但是如果你的编译器在 x64 机器上作为 x86 程序运行,即使这个假设也会被打破。
在MSDOS中的指令代码是16 bit | 2 Bytes
。
因此,最大整数值为 16bit
个整数。
到目前为止我分析的内容:
The keyword
int
differs from compiler to compiler. Turbo C is a16 bit
compiler so it compiles the code into a16 bit
machine code for the processor!As we all know, a compiler will convert the code to a machine code in order to work.
Same applies for GCC.
我们今天使用的计算机是 32/64
位。
编译器应该支持使任何应用程序正常工作的体系结构。
- GCC 是
32/64 bit
编译器。所以,sizeof(int)
是4 Bytes
. - Turbo C 是
16bit
编译器。所以,sizeof(int)
是2 Bytes
.