3 ms·
size_t is unsigned? Since when?
by andi999 6y ago
size_t is unsigned? Since when?
- nikki93 6y agoCouldn't find an online version of the C standard with links to parts of it, but here's one for C++: http://eel.is/c++draft/support.types#layout-3 http://eel.is/c++draft/support.types#layout-3 > The type size_t is an implementation-defined unsigned integer type that is large enough to contain the size in bytes of any object ([expr.sizeof]).
- moonchild 6y agoIt always has been. C89, 4.1.5[1]: > The type are [...] size_t which is the unsigned integral type of the result of the sizeof operator (Emphasis mine.) 1. https://port70.net/~nsz/c/c89/c89-draft.html#4.1.5 https://port70.net/~nsz/c/c89/c89-draft.html#4.1.5
- swinglock 6y agoYes. ssize_t is signed.
- moonchild 6y agossize_t should never be used. It's not guaranteed to have a full negative range, only to be able to represent -1. Use ptrdiff_t as a signed size type.
- AbacusAvenger 6y agoOut of curiosity, do you know of any implementations where ssize_t has that kind of range limitation?
- moonchild 6y agoNope. But I do know of at least one implementation where it's not present at all—msvcrt. ssize_t isn't specified in the c standard, it's part of posix. ptrdiff_t is standard.