News for hackers. Stuff that matters.
Re:Matt Godbolt sold me on Rust by showing me C++ by trealira on Tuesday May 06, 2025 @05:11PM (#43909686)
You can set a flag for that: https://doc.rust-lang.org/rustc/codegen-options/index.html#o...

By default, they're on during debug mode and off in release mode.

Re:Matt Godbolt sold me on Rust by showing me C++ by codedokode on Wednesday May 07, 2025 @05:34AM (#43913716)
The choice doesn't make sense because you want the program to always behave correctly and not only during development.
Re:Matt Godbolt sold me on Rust by showing me C++ by lytedev on Wednesday May 07, 2025 @10:55AM (#43916558)
Eh, maybe. There's a performance tradeoff here and maintainers opted for performance. I'm sure many folks would agree with you that it was the wrong choice, and I'm sure many folks would disagree with you that it was the wrong choice.

There are also specific methods for doing *erflow-checked arithmetic if you like.

Re:Matt Godbolt sold me on Rust by showing me C++ by codedokode on Wednesday May 07, 2025 @01:51PM (#43918689)
Why should there be a performance tradeoff? Because Intel CPU doesn't have add-with-overflow-check instruction, we make our languages less safe?
Re:Matt Godbolt sold me on Rust by showing me C++ by genrilz on Wednesday May 07, 2025 @05:17PM (#43920644)
Actually, the x86 'ADD' instruction automagically sets the 'OF' and 'CF' flags for you for signed and unsigned overflow respectively [0]. So all you need to do to panic would be to follow that with an 'JO' or 'JB' instruction to the panic handling code. This is about as efficient as you could ask for, but a large sequence of arithmetic operations is still going to gum up the branch predictor, resulting in more pipeline stalls.

[0]: https://www.felixcloutier.com/x86/add