Conversion from signed to unsigned is implicit and silent. The expression being converted to your "can never be negative" type isn't nonnegative!!! Its value drastically changes; e.g. -3 becomes a huge number.
Re:Almost Always Unsigned
by snovv_crash on Sunday January 02, 2022 @04:38PM
(#29774212)
Not if you pass -Wconversion to GCC
Clearly defined, but very inconvenient and makes it too easy to write buggy code that looks correct on surface.
Inconvenient to whom? It’s pretty inconvenient not to do that if you eg have strict memory/performance requirements.
C made the right tradeoff IMO. You can protect yourself against overflow if you need to, but if it always signals errors you can’t turn that off.
In terms of the C standard, "3-4" for unsigned ints is modular arithmetic, and the "wrong thing" is assuming that it will do anything other than wrap around. This is very clearly defined, and implied whenever you see an arithmetic expression on unsigned integers.