3 ms·
There’s also Rust’s half-measure of overflow in release mode, panic in debug mode.
by avgcorrection 3y ago
There’s also Rust’s half-measure of overflow in release mode, panic in debug mode.
- wongarsu 3y agoIt takes two lines in your Cargo.toml to turn overflows into panics in release mode in rust, if you don't mind the performance hit. Or more sensibly you can set clippy lints to disallow any operation that may overflow, forcing you to specify the desired behavior (either with the .{wrapping,checking,saturating}_{sub,add,mul,div} functions or the Saturating<Type> etc wrappers)
- avgcorrection 3y agoOkay thanks.
- int_19h 3y agoSimilarly, with C#, you can compile with exception-on-overflow for integers. This is all great, but this should really be the default behavior for basic arithmetic operators, even in release builds. For cases where you want overflow (or saturation, or UB) there should really be distinct operators. Maybe something like <+> for wraparound, [+] for saturation etc.