r/ProgrammingLanguages • 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

115 comments sorted by

View all comments

Show parent comment

3

u/jonathancast globalscript May 04 '26

C and C++ already have typed integer constants: 0U, 0L, etc.

Probably needs explicit size_t and ssize_t versions (and explicit size versions? E.g., an explicit 64- or 128-bit version) but it shows the issue is not unsolvable.

(I know about this because Java allows implicit conversion of int to long but does not allow implicit conversion of int to Long. I guess they reconsidered (even widening) implicit conversions at some point.)

3

u/Lurkernomoreisay May 04 '26

c++ 23 added 0z and 0uz for ssize_t and size_t

2

u/mocompute May 04 '26

So, I also added types integer constants with suffixes, but it turned out practically that it wasn't needed, because inference took care of things. However, when I want a size_t explicitly, I usually prefer to add a type annotation to the declaration, because it's more visible.

x: CSize := 0 is equivalent to x := 0zu so I guess it's a matter of taste.

-1

u/Guvante May 04 '26

Making the user do the work isn't a solve it is a workaround.

Yes it is less ugly than static_cast<unsigned long long>(0); but given how that is almost always compiled out it sucks that it takes non zero effort.