Hacker News new | ask | show | jobs
by zRedShift 1717 days 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.

2 comments

Right, 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.
Indeed, 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.