Conversation
Notices
-
Embed this notice
Alexandre Oliva (lxo@gnusocial.net)'s status on Thursday, 12-Jan-2023 03:52:17 JST Alexandre Oliva
signed integer overflow invokes undefined behavior in both C and C++
but it's true that there are plenty of unwarranted assumptions in programs. so many would be surprised when int is not 32-bits wide, or when long isn't 64-bits wide...-
Embed this notice
🇺🇦 haxadecimal (brouhaha@mastodon.social)'s status on Thursday, 12-Jan-2023 03:52:19 JST 🇺🇦 haxadecimal
It's unfortunate that the world standardized on integer overflow not giving an error. Error on integer overflow should have been the default behavior, with programmers having to explicitly choose wrapping without overflow when that was desired.
Of course, that would also have required explicit signed and unsigned arithmetic operations, because overflow (and underflow) differ for signed vs. unsigned.
Now the no-overflow-error behavior is entrenched in C and C++.翠星石 repeated this.
-
Embed this notice