3 ms·
With default options, Rust programs overflow in a limited way most people call 'safe', and C++ programs that would overflow have undefined behavior which is ver
by Dylan16807 5y ago
With default options, Rust programs overflow in a limited way most people call 'safe', and C++ programs that would overflow have undefined behavior which is very unsafe.
> The failure cases for mistaken wrapping and "mistaken undefined" (the latter meaning that the compiler is allowed to assume that overflow cannot happen) are not different.
They are extremely different. You still get a number with overflowing, and most of the time it's the number you want. If you expect wrapping, it will always be the number you want. Undefined behavior can be much more broken, and it will actively defy expectations.
No language will force you to write correct code. Safety is related but not a synonym for correct.