ant2009 ant2009 - 1 month ago 19
C Question

Is size_t portable?

gcc 4.4.1
C99

I am using size_t and size_t is a unsigned int. However, that depends if you are running 32 bit or 64 bit.

I will be using size_t to store the size of a buffer.

So I don't think this would be very portable if using across architectures.

Just a question, with using size_t on either a 32 or 64 bit. What situations would cause the most serious problem?

Many thanks,

Answer

size_t is guaranteed to be able to hold the number of bytes of any object on your implementation. That's why the return type of sizeof is size_t.

So yes, it's portable.