This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: signed is undefined and has been since 1992 (in GCC)
- From: Olivier Galibert <galibert at pobox dot com>
- To: Morten Welinder <mwelinder at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 28 Jun 2005 19:23:33 +0200
- Subject: Re: signed is undefined and has been since 1992 (in GCC)
- References: <118833cc050628095953822bab@mail.gmail.com>
On Tue, Jun 28, 2005 at 12:59:10PM -0400, Morten Welinder wrote:
> > In particular, a very large number of C and C++ programs are written
> > with the assumptions:
>
> >- signed and unsigned types are modulo, except in loop induction
> > variables where it's bad taste
>
> Well, as demonstrated by INT_MIN/-1, gcc has NEVER fulfilled such assumptions
> on i86 and, quite likely, neither has or will any other compiler. The runtime
> penalty would be too big and hurt performance numbers.
I meant "bad taste to rely on that", sorry. Not that it shouldn't
overflow, but rather that overflowing shouldn't happen in a
well-behaving program and and the compiler is allowed to go and slap
you if it happens.
> What I believe you can find examples of is that the more restricted claim of
> "addition and perhaps subtraction of signed numbers is modulo" is being
> assumed. That's cheap since (for 2-complement) signed addition is the same
> operation as unsigned addition.
Yes.
OG.