You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many POSIX functions return ssize_t (such as read) because they want -1 to mean an error. This means that all that space needed by unsigned isn't needed for these. Why stop there? How about the maximum size of things is @max_value(isize) rather than @max_value(usize).
POSIX printf returns int. Negative is error, positive is byte count printed. We want a similar thing, but we'd probably use isize.
Iterating backwards to 0 for unsigned integers is tricky.
Arguments in favor of unsigned integers for array sizes:
Array lengths don't really have a sign. They can't be negative. So unsigned is more correct.
2x the maximum value. On a 32-bit system, byte arrays would be limited to 2GB in length for signed size.
Manual assertions/checks needed when an unsigned number is expected. (assert(num_bytes_to_print >= 0);)
Passing a signed number to an unsigned type in C (e.g. size_t) requires a cast.
The text was updated successfully, but these errors were encountered:
andrewrk
added
the
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
label
Jan 11, 2016
andrewrk
changed the title
Signed integers for sizes of things?
Signed integers for sizes of things
Jan 11, 2016
Arguments in favor of signed integers for array sizes:
ssize_t
(such asread
) because they want -1 to mean an error. This means that all that space needed by unsigned isn't needed for these. Why stop there? How about the maximum size of things is@max_value(isize)
rather than@max_value(usize)
.int
. Negative is error, positive is byte count printed. We want a similar thing, but we'd probably use isize.Arguments in favor of unsigned integers for array sizes:
assert(num_bytes_to_print >= 0);
)The text was updated successfully, but these errors were encountered: