4 ms·
> I'm reasonably sure signed integer overflow is implementation defined to mean twos complement overflow on x86. I think you're mistaken, or are using implemen
by denotational 5y ago
> I'm reasonably sure signed integer overflow is implementation defined to mean twos complement overflow on x86.
I think you're mistaken, or are using implementation-defined in a colloquial sense; the term implementation-defined has a specific technical meaning in the context of C that isn't the same as how it might be used in common parlance.
The distinction between implemention-defined behaviour and undefined behaviour is extremely important, because as soon as you invoke the latter your program "doesn't exist" and a standards-conforming compiler is allowed to do whatever it wants.
Signed integer overflow is explicitly given as an example of UB by the C standard [1], in 3.4.3:
> 3 EXAMPLE An example of undefined behavior is the behavior on integer overflow.
By my reading, the specific part of the standard that makes signed overflow UB is in 6.5:
> 5 If an exceptional condition occurs during the evaluation of an expression (that is, if the
result is not mathematically defined or not in the range of representable values for its
type), the behavior is undefined.
This is completely unrelated to what actually happens when you issue an ADD instruction on an x86; the C standard doesn't care about this.
[1] : http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf