As title: is size_t always unsigned, i.e. for size_t x
, is x
always >= 0
?
According to the standard it is unsigned, however I recall that some older implementations used a signed type for the typedef.
From an older GCC doc:
There is a potential problem with the size_t type and versions of GCC prior to release 2.4. ANSI C requires that
size_t
always be an unsigned type. For compatibility with existing systems' header files, GCC definessize_t
instddef.h
to be whatever type the system'ssys/types.h
defines it to be. Most Unix systems that definesize_t
insys/types.h
, define it to be a signed type. Some code in the library depends onsize_t
being an unsigned type, and will not work correctly if it is signed
I'm not sure how important it would be to guard against that. My code assumes it's unsigned.