News for hackers. Stuff that matters.
Re:Undefined Behavior in 2017 by sp332 on Wednesday July 05, 2017 @10:47AM (#14702780)
You could test whether overflow is going to happen first. Or use a math library that explicitly overflows with predictable results.
Re:Undefined Behavior in 2017 by dullgiulio on Wednesday July 05, 2017 @01:50PM (#14704627)
I know very few languages that do that. Even Rust doesn't when compiled for release. All for performance reasons.
Re:Undefined Behavior in 2017 by steveklabnik on Wednesday July 05, 2017 @02:22PM (#14704911)
Some additional points:

* It's not UB in Rust, it's guaranteed to be two's compliment overflow.

* It's still a "program error" and debug builds are required to panic.

* Non-debug builds are allowed to either panic or do the overflow, for performance reasons, as you mention. If it was feasible to always panic we'd do that; the current wording allows us to change it to do so in the future if it becomes feasible.

* If you want to do a checked add, you can, it's just not the default.

Re:Undefined Behavior in 2017 by sp332 on Wednesday July 05, 2017 @03:01PM (#14705215)
I might have lost the point in this long thread, but I'm pretty sure the suggestion was just to add it as an optional flag.