3 ms·
The fact that integer overflow is undefined in C++ is ugly, but this leaves the solution of this problem to the compiler. The final behavior is decided by the
by adrian_b 5y ago
The fact that integer overflow is undefined in C++ is ugly, but this leaves the solution of this problem to the compiler.
The final behavior is decided by the programmer, by using or not using "-fsanitize=signed-integer-overflow" or equivalent options for the compilation.
So after the programmer makes a decision, the behavior in C++ is defined and it is either like in debug Rust or like in release Rust, depending on the programmer's decision.
While I hate undefined behaviors in C/C++, I prefer to be able to make my own decisions on the behavior of integer overflow, instead of being forced by Rust to ignore overflows in release builds.
Edit:
Thanks for the Cargo link. If you can change the overflow checking option in the Cargo profile, then there remains absolutely no difference between C++ and Rust regarding integer overflow.
The Rust RFC "Integer overflow #560" is totally misleading in this case.
- SAI_Peregrinus 5y agoRust integer overflow is never undefined behavior. It'll either wrap (default release mode) or trap (debug mode, release mode with the flag on). C++ defaults to it being undefined.