Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

All of this puts the onus on the programmer to write strictly conforming applications code, with or without the help of the compiler. Because performance is a primary emphasis of the C language, this situation is likely to get worse before it gets better.

...

This code tests for signed integer overflow by testing to see if a + 100 > a. This test cannot evaluate to false unless an integer overflow occurs. However, because a conforming implementation is not required to generate code for undefined behavior, and signed integer overflow is undefined behavior, this code may be compiled out. For example, gcc version 4.1.1 optimizes out the assertion for all optimization levels and gcc 4.2.3 optimizes out the assertion for program compiled with -O2 level optimization and higher.

On some platforms, the integer overflow will cause the program to terminate (before it has an opportunity to test).

Compliant Solution

This compliant solution does not depended upon undefined behavior so a compliant solution is required to generate code for the overflow test in the assertion.

...