[PATCH] Document arithmetic overflow semantics

Roger Sayle roger@www.eyesopen.com
Thu Feb 13 22:54:00 GMT 2003


On Thu, 13 Feb 2003, Richard Henderson wrote:
> On Fri, Feb 14, 2003 at 05:27:46AM +1100, Fergus Henderson wrote:
> > `+wrap' is associative ...  But `+undef' is not
>
> Certainly it is.  It's undefined.  We can get whatever results
> are most convenient.

Alas not.  a +undef (b +undef c) is not guaranteed to be the same
as (a +undef b) +undef c!  Consider a = 100, b = 30, c = -50 for
signed chars.  Notice that the first expression doesn't overflow,
but the second does, invoking the "we can get whatever results
are most convenient" instaed of being guaranteed to produce 80.


Undefined overflow is so non-intuitive, anyone can make a mistake.

Roger
--



More information about the Gcc mailing list