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
37
u/WittyStick May 03 '26 edited May 03 '26
The problem is implicit conversion at the same bit width.
There should never be an implicit conversion from
signed->unsigned, unless preceded with a check>= 0.There should only be an implicit conversion
unsigned->signedwhere the unsigned representation is strictly smaller than the signed one.That's assuming two's complement, which is a reasonable assumption.
I use this in my numerical tower, not with arbitrary bit width types, but the common power of 2 types we typically use.
Where
<:is the subtyping relation. Upcasts are implicit, but all downcasts are explicit.Sizes should be unsigned. Signed sizes are a workaround for other problems in a type system.