News for hackers. Stuff that matters.
Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by Animats on Thursday June 22, 2017 @02:02PM (#14614073)
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.

There are no comments on this comment yet.