I am getting confused with size_t
in C. I know that it is returned by the sizeof
operator. But what exactly is it? Is it a data type?
Let\'
size_t
and int
are not interchangeable. For instance on 64-bit Linux size_t
is 64-bit in size (i.e. sizeof(void*)
) but int
is 32-bit.
Also note that size_t
is unsigned. If you need signed version then there is ssize_t
on some platforms and it would be more relevant to your example.
As a general rule I would suggest using int
for most general cases and only use size_t
/ssize_t
when there is a specific need for it (with mmap()
for example).