size_t vs. uintptr_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

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!-)

Leave a Comment