|Оценка:||57 (5) +1|
Allow the compiler to assume strict signed overflow rules, depending on the language being compiled.
For C (and C++) this means that overflow when doing arithmetic with signed numbers is undefined, which
means that the compiler may assume that it does not happen. This permits various optimizations. For
example, the compiler assumes that an expression like "i + 10 > i" is always true for signed "i". This
assumption is only valid if signed overflow is undefined, as the expression is false if "i + 10"
overflows when using twos complement arithmetic. When this option is in effect any attempt to
determine whether an operation on signed numbers overflows must be written carefully to not actually
This option also allows the compiler to assume strict pointer semantics: given a pointer to an object,
if adding an offset to that pointer does not produce a pointer to the same object, the addition is
undefined. This permits the compiler to conclude that "p + u > p" is always true for a pointer "p" and
unsigned integer "u". This assumption is only valid because pointer wraparound is undefined, as the
expression is false if "p + u" overflows using twos complement arithmetic.
See also the -fwrapv option. Using -fwrapv means that integer signed overflow is fully defined: it
wraps. When -fwrapv is used, there is no difference between -fstrict-overflow and -fno-strict-overflow
for integers. With -fwrapv certain types of overflow are permitted. For example, if the compiler gets
an overflow when doing arithmetic on constants, the overflowed value can still be used with -fwrapv,
but not otherwise.
The -fstrict-overflow option is enabled at levels -O2, -O3, -Os.
You will always get what you always got If you always do what you always did