|
|
|
|
|
by renox
620 days ago
|
|
> integer overflows panic Not in all the ReleaseFast mode where both signed and unsigned overflow have undefined behaviour. And there's also the aliasing issue, if you have
fn f(a:A, b: b:*A) { b = <>; which value has 'a' when f is called with f(a,a)? }
(not sure about Zig's syntax). That said I agree with your classification (safer than C but isn't as safe as Rust) |
|
This is probably not what you wanted, your code has a bug (if it was what you wanted, you should use the Wrapping type wrapper which says what you meant, not just insist this code must be compiled with specific settings) but you didn't have to pay for checks and your program continues to have defined behaviour, like any normal bug.
It is very rare that you need the unchecked behaviour for performance. Rare enough that although Wrapping and Saturating wrappers exist in Rust, even the basic operations for unchecked arithmetic are still nightly only. Most often what people meant is a checked arithmetic operation in which they need to write code to handle the case where there would be overflow, not an unchecked operation, Rust even has caution notes to guide newbies who might write a manual check - pushing them towards the pit of success - hey, instead of your manual check and then unsafe arithmetic, why not use this nice checked function which, in fact, compiles to the same machine code.