我在不同的来源(例如维基百科:http://en.wikipedia.org/wiki/C_variable_types_and_declarations#Size)读过几次,在 C 中,long long 不小于 long,long 不小于 int,int 不小于一个短片。
但是,我已经在 C90 和 C99 标准中查找了这一点,并没有找到相应的条款。我发现只有 C90 和 C99 指定了最小字体大小(C90 和 C99 标准中的第 5.2.4.2.1 节),但没有指定它们相互之间的大小。我是否遗漏了标准中的某些内容?
最佳答案
6.3.1.1 定义了任意两种整数类型的相对整数转换等级。这是一个抽象概念,仅用于定义两种类型之间的关系;没有定义为任何类型的 rank 的值。
6.2.5p8 说:
For any two integer types with the same signedness and different integer conversion rank (see 6.3.1.1), the range of values of the type with smaller integer conversion rank is a subrange of the values of the other type.
它没有说明它们的相对大小,事实上,从理论上讲,符合要求的(但故意违背常理的)实现有 sizeof (short) > sizeof (int)
。仅当 short
具有比 int
更多的填充位(对值没有贡献的位)时,这才有可能。这不太可能;大多数实现根本没有填充位,而且我知道没有实现中整数类型范围的关系与其大小的关系不同。
关于c - "int"真的需要至少与 C 中的 "short"一样大吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10774416/