3 ms·
For C, the standard specifies that unsigned arithmetic wraps around, while integer arithmetic overflow is undefined. I once suggested, back when there were mac
by Animats 9y ago
For C, the standard specifies that unsigned arithmetic wraps around, while integer arithmetic overflow is undefined.
I once suggested, back when there were machines that weren't byte-oriented or twos complement, that wraparound arithmetic should be requested with
unsigned int x;
x = (x + 1) % 0xffff;
or something similar. That way, you get the same result on all platforms, regardless of word length. If the hardware can truncate cheaply, the compiler can optimize "%" such expressions easily. Other than that, overflow should be an error.