This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] Document arithmetic overflow semantics
- From: Roger Sayle <roger at www dot eyesopen dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org, <gcc at gcc dot gnu dot org>
- Date: Thu, 13 Feb 2003 15:02:53 -0700 (MST)
- Subject: 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.