Re:My personal C coding style as of late 2023
by harpiee on Monday October 09, 2023 @04:24AM
(#37818251)
With unsigned you can actually check for overflow yourself very easily
And bounds checks are just a single comparisons against an upper bound (handles both over and underflow)
Prior to C23 (stdckdint.h) its very error prone to check for signed overflow since you have to rearrange equations to make sure no operation could ever possibly overflow.
[ Parent
| on HN ]
Re:My personal C coding style as of late 2023
by uecker on Monday October 09, 2023 @02:32PM
(#37823588)
You can write correct programs with both. The reality is that people often fail to do this. But you can automatically detect signed overflow and protect against it, while unsigned wrap detected at run-time could be a bug or could be just fine (e.g. because you did your own "overflow" check and handle it correctly). This makes it extremely hard to find unsigned wraparound bugs and impossible to trap at run-time.