This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Document arithmetic overflow semantics


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
--


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]