News for hackers. Stuff that matters.
Re:Essential C (2003) [pdf] by andi999 on Wednesday September 02, 2020 @07:42PM (#24359466)
size_t is unsigned? Since when?
Re:Essential C (2003) [pdf] by moonchild on Wednesday September 02, 2020 @11:00PM (#24360443)
It 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

Re:Essential C (2003) [pdf] by nikki93 on Wednesday September 02, 2020 @07:46PM (#24359489)
Couldn'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

> 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]).

Re:Essential C (2003) [pdf] by swinglock on Thursday September 03, 2020 @01:09AM (#24360955)
Yes. ssize_t is signed.
Re:Essential C (2003) [pdf] by moonchild on Thursday September 03, 2020 @01:27AM (#24361014)
ssize_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.

Re:Essential C (2003) [pdf] by AbacusAvenger on Thursday September 03, 2020 @04:02AM (#24361798)
Out of curiosity, do you know of any implementations where ssize_t has that kind of range limitation?
Re:Essential C (2003) [pdf] by moonchild on Thursday September 03, 2020 @04:13AM (#24361848)
Nope. 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.