3 ms·
Well, for one, in the Rust version, check(i32::MIN) will return false if built with overflow checks disabled (the default for release builds). C++ will of cour
by zRedShift 5y ago
Well, for one, in the Rust version, check(i32::MIN) will return false if built with overflow checks disabled (the default for release builds).
C++ will of course always return true.
- zozbot234 5y agoRight, wrt. C++ the "square" operation on signed integers makes the whole program undefined if overflow occurs, whereas the Rust equivalent is defined to wrap using two's complement arithmetic. And of course the square of INT32_MIN cannot be represented in int32_t.
- einpoklum 5y agoIndeed, but then you are partially "un-rustifying" things. That is, the author specifically boasts in the article that: > In Rust, an undefined-behavior arithmetic issue like that is literally impossible. ... but that's only true if the safeties are on, specifically overflow checking.