C语言 C中整数的大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7180196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Size of integer in C
提问by 0x07FC
Possible Duplicate:
Does the size of an int depend on the compiler and/or processor?
可能的重复:
int 的大小是否取决于编译器和/或处理器?
Does the size of Integer depend on Compiler or on OS or on Processor? What if I use gcc on both 32 bit OS or 64bit OS running either on 32 bit machine or 64 bit machine(only 64 bit OS in this case).
Integer 的大小是否取决于编译器或操作系统或处理器?如果我在 32 位操作系统或 64 位操作系统上使用 gcc 会怎样,运行在 32 位机器或 64 位机器上(在这种情况下只有 64 位操作系统)。
采纳答案by pmg
Depends on compiler options.
Of course it depends on the compiler itself too.
But the compiler was made for a specific OS, so it depends on the OS
And / or
The compiler was made for a specific processor, so it depends on the processor
取决于编译器选项。
当然,这也取决于编译器本身。
但是编译器是为特定的操作系统制作的,所以它取决于操作系统
和/或
编译器是为特定的处理器制作的,所以它取决于处理器
回答by Rudy Velthuis
It depends on the combination of compiler, processor and OS.
这取决于编译器、处理器和操作系统的组合。
For instance, on a 64 bit Intel CPU, in 64 bit mode, the size of a long intin Windows is 4 byte while in Linux and on the Mac it is 8 byte. intis 4 bytes in all three OSes on Intel.
例如,在 64 位 Intel CPU 上,在 64 位模式下,a 的大小long int在 Windows 中为 4 字节,而在 Linux 和 Mac 上为 8 字节。int在 Intel 的所有三个操作系统中都是 4 个字节。
The compiler implementer also has a choice, but usually uses what the OS uses. But it could well be that a compiler vendor that has C compilers for all three platforms decides to use the same sizes in all three.
编译器实现者也有选择,但通常使用操作系统使用的。但很可能一个编译器供应商拥有适用于所有三个平台的 C 编译器,决定在所有三个平台中使用相同的大小。
Of course, it doesn't make sense to make int4 bytes (although it would be possible) on a 16 bit CPU.
当然,int在 16 位 CPU 上生成 4 个字节(尽管可能)是没有意义的。
So it depends on all three things you mention.
所以这取决于你提到的所有三件事。
回答by progrmr
The size of int, long, etc, depends on the compiler, but the compiler implementer will choose the best size for a particular processor and/or OS.
int、long 等的大小取决于编译器,但编译器实现者将为特定处理器和/或操作系统选择最佳大小。
回答by JaredPar
The size of an int, and pretty much every other type, in C is implementation defined. Certain compilers may make guarantees on specific platforms but this is implementation dependent. It's nothing you should ever rely on
an 的大小int,以及几乎所有其他类型,在 C 中都是实现定义的。某些编译器可能会在特定平台上做出保证,但这取决于实现。这不是你应该依赖的东西
回答by Stephen Canon
Does the size of Integer depands on Compiler or on OS or on Processor?
Integer 的大小是否取决于编译器、操作系统或处理器?
Yes. It can depend on any of those things.
是的。它可以依赖于任何这些东西。
It is actually defined by the platform ABI, which is set by the compiler and runtime libraries, but compilers use different ABIs on different OS's or architectures.
它实际上是由平台 ABI 定义的,它由编译器和运行时库设置,但是编译器在不同的操作系统或架构上使用不同的 ABI。
回答by Vinicius Kamakura
It depends on the system. And by system I mean any combination of processor and operating system, but it usually is bound to the "natural" integer size of the processor in use.
这取决于系统。我所说的系统是指处理器和操作系统的任何组合,但它通常与所用处理器的“自然”整数大小有关。

