C++ vs Rust ( This is not a fight area :) )

There isn't, and more generally there will never be a flag to rustc that adds UB to safe code (the way -ffast-math makes otherwise-safe things UB in C).

You always have to change the code if you want to introduce UB.

Well, this compiles to just a mov, for example:

use std::num::NonZero;
#[unsafe(no_mangle)]
pub fn square(num: i32, fac: NonZero<i32>) -> i64 {
    (num as i64 * fac.get() as i64)/(fac.get() as i64)
}

https://rust.godbolt.org/z/Wcb8Eqs4h

Based on how prevalent crashes are in games, I never trust people that say they "know" something won't happen in a game.

11 Likes