Reputation:
I've been getting a lot of criticism for using uint
instead of size_t
, but every time I check the toolchain I am working with turns out size_t
is defined as a uint
.
Are there any compiler implementations where size_t
is actually not a uint
? What are the grounds for that criticism?
Upvotes: 1
Views: 1868
Reputation: 129364
size_t
is the "size matching the largest possible address range you can use in the machine" (or some words to roughly that effect).
In particular, size_t
will be 64 bits on a 64-bit machine, and 32 bits on a 32-bit system.
I'm assuming uint
is short of unsigned int
, which is pretty much universally 32 bits (these days, some older systems would be using 16-bit integers). So on a 64-bit system, an unsigned int
will be 32 bits still, although memory allocations, strings, etc can be larger than 32 bits in size - which would cause problems if you are trying to use uint
for the size.
Upvotes: 6