In C:
There are 5 standard unsigned integer types:
unsigned charunsigned shortunsigned intunsigned longunsigned long long
with different requirements for their sizes and ranges (in short, each type range is a subset of the next type, but some of them may have the same range).
size_t is a typedef (i.e. an alias) for some unsigned type (perhaps one of the above, but possibly an unsigned extended integer type, although this is unlikely). This is the type specified by the sizeof operator.
On one system, it might make sense to use unsigned int to represent sizes; on the other hand, it makes sense to use unsigned long or unsigned long long . ( size_t unlikely to be either unsigned char or unsigned short , but this is allowed).
The purpose of size_t is to save the programmer from having to worry about which of the predefined types is used to represent sizes.
Code that assumes sizeof gives an unsigned int will not be portable. Code that assumes that it gives size_t will most likely be portable.
Keith Thompson Nov 01 '13 at 17:52 2013-11-01 17:52
source share