4 ms·
Rust does have loop counter overflow.
by Thaxll 1y ago
Rust does have loop counter overflow.
- swiftcoder 1y agoTheoretically you can construct a loop counter that overflows, but I don't that there is any reasonable way to do it accidentally? Within safe rust you would likely need to be using an explicit .wrapping_add() on your counter, and explicitly constructing a for loop that wasn't range-based...
- tekne 1y agoWell, in debug mode yes, but in release mode overflow is wrapping by default unless you explicitly set a flag to make it panic.
- jason_oster 1y agoThis is irrelevant on 64-bit platforms [^1] [^2]. For platforms with smaller `usize`, enable overflow-checks in your release builds. [^1]: https://www.reddit.com/r/ProgrammerTIL/comments/4tspsn/c_it_will_take_approximately_97_years_to_overflow/ https://www.reddit.com/r/ProgrammerTIL/comments/4tspsn/c_it_... [^2]: https://stackoverflow.com/questions/69375375/is-it-safe-to-assume-64-bit-counter-doesnt-suffer-from-overflow https://stackoverflow.com/questions/69375375/is-it-safe-to-a...