更新时间:2023-11-14 22:07:16
size_t
是一种可以保存任何数组索引的类型.这意味着,从逻辑上讲, size_t 应该能够持有任何指针类型
size_t
is a type that can hold any array index. This means that, logically, size_t should be able to hold any pointer type
不一定!回到分段 16 位架构的时代,例如:一个数组可能仅限于单个段(因此 16 位 size_t
可以)但您可以有多个段(因此 32-bit intptr_t
类型将需要选择段以及其中的偏移量).我知道在这些可统一寻址的非分段架构的日子里,这些事情听起来很奇怪,但标准必须满足比2009 年的正常情况"更广泛的需求,你知道!-)
Not necessarily! Hark back to the days of segmented 16-bit architectures for example: an array might be limited to a single segment (so a 16-bit size_t
would do) BUT you could have multiple segments (so a 32-bit intptr_t
type would be needed to pick the segment as well as the offset within it). I know these things sound weird in these days of uniformly addressable unsegmented architectures, but the standard MUST cater for a wider variety than "what's normal in 2009", you know!-)