r/ProgrammingLanguages • u/Nuoji C3 - http://c3-lang.org • May 03 '26
Blog post Unsigned Sizes: A Five Year Mistake
https://c3-lang.org/blog/unsigned-sizes-a-five-year-mistake/
91
Upvotes
r/ProgrammingLanguages • u/Nuoji C3 - http://c3-lang.org • May 03 '26
View all comments
Show parent comment
1
u/WittyStick May 04 '26
That's actually the easiest argument to make - a "negative size" makes zero sense. The size of something is a natural number.
It's the signed size advocates who need to make the justification, and I find their arguments pretty uncompelling - particularly when we fix the implicit conversion issues as described.
The underflow at zero might be an issue for novices - but using signed integers replaces that with overflow at INT_MAX or underflow at INT_MIN. You don't simply remove the problem by making signed sizes - you actually make it more likely that a bug will remain for longer because these cases are less likely to appear in production. Ie, code might work fine for some time, until you scale beyond 2GiB and the bugs start appearing.
Also we have the issue that signed integer under/overflow is UB, where unsigned wrap is well-defined. On x86_64, addition, subtraction and multiplication of signed integers will overflow, but division will trap.