原始数据类型的大小 [英] Size of Primitive data types
问题描述
在究竟是什么基本数据类型的如 INT
的大小取决于?
On what exactly does the size of a primitive data type like int
depend on?
- 编译
- 处理器
- 开发环境
或者是这些或其他因素的组合?结果
在相同的原因的解释将是真正有用的。
Or is it a combination of these or other factors?
An explanation on the reason of the same will be really helpful.
编辑:对不起,confusion..I意味着询问有关吊舱如int原始数据类型,而不是,我明白的POD可以包括结构和结构这是一个完全不同的球赛与填充进来的图片。
我在这里纠正了Q,编辑注应确保对POD的答案不看无关紧要的。
Sorry for the confusion..I meant to ask about Primitive data type like int and not regarding PODs, I do understand PODs can include structure and with structure it is a whole different ball game with padding coming in to the picture. I have corrected the Q, the edit note here should ensure the answers regarding POD don't look irrelevant.
推荐答案
我觉得有两部分这个问题:
I think there are two parts to this question:
-
哪种尺寸的原始类型的允许的是。结果
这是由C指定和C ++标准:在类型已经允许的最小值范围内,他们必须有,这在位隐式地添加一个下限大小的 的(例如长
必须至少为32位符合标准)。结果
该标准不指定字节大小,因为<一个href=\"http://stackoverflow.com/questions/437470/type-to-use-to-re$p$psent-a-byte-in-ansi-c89-90-c/437640#437640\">definition字节来达到的执行,例如字符
是字节,但字节大小(CHAR_BIT
宏)可能是16位。
What sizes primitive types are allowed to be.
This is specified by the C and C++ standards: the types have allowed minimum value ranges they must have, which implicitly places a lower bound on their size in bits (e.g.long
must be at least 32 bit to comply with the standard).
The standards do not specify the size in bytes, because the definition of the byte is up to the implementation, e.g.char
is byte, but byte size (CHAR_BIT
macro) may be 16 bit.
为实现中定义的实际大小。结果
这一点,因为其他的答案已经指出的,是依赖于实现:编译器。和编译器实现,反过来,在很大程度上受目标架构的影响。所以这是合理的,以在相同的操作系统和架构上运行,但有 INT
的不同大小两种编译器。你可以进行的唯一的假设是一个由标准的规定(因为编译器实现它)。结果
还可以有额外的ABI要求(枚举的例如固定的大小)
The actual size as defined by the implementation.
This, as other answers have already pointed out, is dependent on the implementation: the compiler. And the compiler implementation, in turn, is heavily influenced by the target architecture. So it's plausible to have two compilers running on the same OS and architecture, but having different size of int
. The only assumption you can make is the one stated by the standard (given that the compiler implements it).
There also may be additional ABI requirements (e.g. fixed size of enums).
这篇关于原始数据类型的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!