4 ms·
> all you have to do to avoid UB on signed integer overflow is check for overflow before doing the operation All you have to do is add a check for overflow _th
by c4mpute 4y ago
> all you have to do to avoid UB on signed integer overflow is check for overflow before doing the operation
All you have to do is add a check for overflow _that the compiler will not throw away because "UB won't happen"_. The very thing you want to avoid makes avoiding it very hard, and lots of bugs have resulted from compilers "optimizing" away such overflow checks.