This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Document arithmetic overflow semantics
- From: Andrew Haley <aph at redhat dot com>
- To: dewar at gnat dot com (Robert Dewar)
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 13 Feb 2003 19:26:34 +0000 (GMT)
- Subject: Re: [PATCH] Document arithmetic overflow semantics
- References: <20030213190602.CD538F2D5E@nile.gnat.com>
Robert Dewar writes:
> > What do you mean by this, exactly? Java is defied as having signed
> > two's complement arithmetic.
>
> At the implementation level, the difference between signed and unsigned
> arithmetic (for operations like plus and minus) is in whether overflow
> is an issue or not (look for example at the MIPS). The issue of "2-s complement"
> just has to do with how you interpret a bit pattern (i.e. whether all 1's is
> a big number of minus one). If you have wrap around semantics, then, regardless
> of how you choose to interpret the bit patterns, the appropriate run-time
> representation of add/subtract operations is to do unsigned adds with no
> carry around (and no signed overflow detection).
Obviously, but you said
> it seems clear that Java should be using unsigned arithmetic for
> all operations, since that is the way Java is defined.
and clearly this is in incorrect in many cases, for example int->long
conversion and indeed anything that involves integer operands of
different sizes.
Andrew.