3 ms·
> However you do have to be careful in critical code because things like integer overflow can also raise a panic. This is incorrect. Only in debug builds does
by vlovich123 1y ago
> However you do have to be careful in critical code because things like integer overflow can also raise a panic.
This is incorrect. Only in debug builds does it raise a panic. In release Rust has to make the performance tradeoff that C++ does and defines signed integer math to wrap 2’s complement. Only in debug will signed overflow panic. Unsigned math never panics - it’s always going to overflow 2’s complement.
- quotemstr 1y ago> Only in debug builds does it raise a panic. Correctness in debug builds is important, isn't it? That said, panic on integer overflow in debug builds is unfortunate behavior. Overflow should cause an abort, not a panic. > make the performance tradeoff that C++ does and defines signed integer math to wrap 2’s complement In C++, signed overflow is undefined behavior, not wraparound. This property is useful to the optimizer for things like inferring loop bounds. The optimizer has less flexibility in equivalent Rust code.
- AlotOfReading 1y agoWhat's the rationale behind aborting and not panicking in debug? Unwinding and flushing buffers seems like a better default with debug binaries.
- tialaramex 1y agoYou can choose whether panics immediately abort, and you can also choose whether integer overflow panics in releas builds. Personally I would often choose both, overflow panics and also panics abort, so if we overflow we blow up immediately.
- 0x1ceb00da 1y agoYou can enable overflow panics in release build, so if you're a library, you have to play it safe because you don't know how people will build your library.