Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Changing signed integer overflow is extremely stupid considering unsigned integer overflow is what does the wrong thing in C. Just use ubsan.


> unsigned integer overflow is what does the wrong thing in C

You may want to rethink this statement


No, I am correct. Unsigned integer overflow has wrapping overflow semantics. Absolutely idiotic.


So... unsigned overflow is defined, while signed is straight up UB... and for you it's the former that's wrong?


Yes. Most calculations won't do the right thing with wrapping overflow and you'd be better of by them being undefined and tested via the relevant tooling (e.g. ubsan). Those that do should be written in a way to make that explicit.


Compilers can make commutative optimizations with signed integer overflow that is impossible with wrapping semantics. This is why Zig and Carbon both make unsigned integer overflow undefined as well. There is absolutely no advantage in most cases to wrapping semantics unless it is actually required for the algorithm (like some hashing or PRNG functions, for example).




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: