The result of x - y
is defined as the mathematical result of subtracting y
from x
. If the mathematical result can be represented in the result type (int
in this case), then there is no overflow.
A compiler is free to transform the expression in any way it likes, such as by changing
x - y
to
x + (-y)
but only if the transformation keeps the same behavior in cases where the original behavior is well defined. In the case of y == INT_MIN
, it can still perform the transformation as long as the undefined behavior of evaluating -INT_MIN
yields the same end result (which it typically will).
To answer the question in the title:
Is INT_MIN subtracted from any integer considered undefined behavior?
INT_MIN - INT_MIN == 0
, and cannot overflow.
Incidentally, I think you mean int
rather than "integer". int
is just one of several integer types.