Integer overflow in C: standards and compilers

Take a look at -ftrapv and -fwrapv:


This option generates traps for signed overflow on addition, subtraction, multiplication operations.


This option instructs the compiler to assume that signed arithmetic overflow of addition, subtraction and multiplication wraps around using twos-complement representation. This flag enables some optimizations and disables other. This option is enabled by default for the Java front-end, as required by the Java language specification.

Leave a Comment