3 ms·
Depending on how you turn your head and squint, overflow is still well-defined: if I add a to b and it overflows to c, it still overflows to the same c every ti
by shadowgovt 3y ago
Depending on how you turn your head and squint, overflow is still well-defined: if I add a to b and it overflows to c, it still overflows to the same c every time. That means addition is sound in that architecture, it just has surprising consequences and some properties one would expect naively to hold for positive-integer arithmetic don't hold for the computer addition operation (such as c > a && c > b for all a > 0 and b > 0).
- staunton 3y agoC/C++ (the standard) makes no claims about what happens if you overflow integers. The program might set all your variables in the whole program to zero if it likes. Of course the compiler vendors wouldn't do that but they're allowed to. That's what "undefined" means at least in C/C++.
- Kamq 3y ago> C/C++ (the standard) makes no claims about what happens if you overflow integers. It makes no claims on what happens when you overflow signed integers. Unsigned integer wrapping is specified by section 6.2.5, paragraph 9 of the C standard.