3 ms·
We're talking about Rust, not C/C++.
by chaosite 8y ago
We're talking about Rust, not C/C++.
- OskarS 8y agoYeah, but I interpreted the question as "is that how it should work?", and then it's useful to compare with different languages. My point was that this is standard behaviour, but there's a slight quirk in C when the ints are signed.
- gpm 8y agoJust to record the difference. Unsigned and signed overflow in rust are both well defined to do one of two things, panic or wrap. If debug assertions are enabled they are defined to panic. In practice if debug assertions are not enabled they will wrap, but I believe that is technically subject to change (into a panic). It will realistically only change if the hardware gets much better at catching overflows quickly. A panic is usually like a exception that you are really not expected to ever catch except at thread boundaries. You can turn them into a immediate process exit with a compiler flag.
- mmirate 8y ago> except at thread boundaries Also at FFI boundaries. (i.e. a panicky Rust function, supplied to foreign code as a callback)
- steveklabnik 8y ago> I believe that is technically subject to change Yes, that's correct.