14 ms·
Quoting one of these comments: > The argument with substracting 5 from 3 is not an argument against using unsigned. When you use signed you can run into a simi
by jcelerier 5y ago
Quoting one of these comments:
> The argument with substracting 5 from 3 is not an argument against using unsigned. When you use signed you can run into a similar problem when the result underflows. This happens much less frequent and causes UB, at INT_MIN, which is the worst kind of bug. The bug is often not triggered durring testing and you will only notice it when it is too late.
The "When you use signed you can run into a similar problem" part is just not true in our world. 3 - 5 happens much more often than anything that may cause signed .*flow.
"signed underflow" "bug report"
yields 8 results on google FFS
- leni536 5y agoNo such thing as "underflow" for integers. Signed integers overflow in both directions. Underflow is a floating point concept. Edit: https://en.m.wikipedia.org/wiki/Arithmetic_underflow https://en.m.wikipedia.org/wiki/Arithmetic_underflow
- cies 5y agoSo what about an unsigned int going below zero? I think most in the comments here mean that by "underflow", but i could be mistaken (and it should correctly be called "overflow" as well). I agree with the WP article saying integers more correctly "wrap around" (than overflow).
- leni536 5y agoThe C standard only calls certain integer arithmetic to "overflow" if it results in undefined behavior. In that sense undefined integer arithmetic never overflows, but they "wrap around", as the behavior is defined there. I can't actually find a normative definition for "overflow" in the C or C++ standards, but there are sections and notes that describe this interpretation: C++: https://eel.is/c++draft/full#basic.fundamental-note-2 https://eel.is/c++draft/full#basic.fundamental-note-2 C: http://web.archive.org/web/20211231011139/https://cigix.me/c17#6.2.5.p9 http://web.archive.org/web/20211231011139/https://cigix.me/c... There can be subtle differences between various definitions of "overflow", and I imagine there could be other subtly different definitions outside C and C++. But "underflow" is exclusively a floating point concept, as far as I know.