为什么当为size_t INT就足够了数组的大小? [英] Why size_t when int would suffice for the size of an array?
问题描述
C标准保证了 INT
能够每一个可能的数组大小商店。至少,这是我从阅读理解§6.5.2.1条第1款(数组下标约束):
The C standard guarantees that an int
is able to store every possible array size. At least, that's what I understand from reading §6.5.2.1, subsection 1 (Array subscripting constraints):
其中前pressions应有类型'指针对象的类型'',在其他前pression应的
有整型,并且结果的类型''类型''。
One of the expressions shall have type ‘‘pointer to object type’’, the other expression shall have integer type, and the result has type ‘‘type’’.
由于我们将使用 INT
能够像数组下标,为什么我们应该使用为size_t
的大小来确定一个数组的?
Since we shall use int
s as array subscripts, why are we supposed to use size_t
to determine the size of an array?
为什么的strlen()
收益为size_t
在 INT
就足够了?
Why does strlen()
return size_t
when int
would suffice?
推荐答案
术语整型并不意味着 INT
- 例如,字符
和短
是整数类型。
The term "integer type" doesn't mean int
- for example, char
, and short
are integer types.
因为你可以使用 INT
来标为数组并不一定意味着它可以到达所有可能的数组元素。
Just because you can use an int
to subscript an array doesn't necessarily mean that it can reach all possible array elements.
更具体地说约为size_t
与 INT
,其中一个例子是平台,其中 INT
可能是一个16位的类型和为size_t
可能是一个32位的类型(或者更常见的32位 INT
和64位为size_t
今天的64位平台的差异)。
More specifically about size_t
vs. int
, one example would be platforms where int
might be a 16-bit type and size_t
might be a 32-bit type (or the more common 32-bit int
vs 64 bit size_t
difference on today's 64-bit platforms).
这篇关于为什么当为size_t INT就足够了数组的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!