Morten Welinder wrote on 28/06/2005 19:59:10:
> > 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.
>
> 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.
>
> Morten
This is problematic as Joe Buck has shown:
; /* int a, b, c; */
; if (b > 0) {
; a = b + c;
; int count=0;
; for (int i = c; i <= a; i++)
; count++;
; some_func(count);
; }
Can be optimized to
; if (b > 0)
; some_func(b+1);
Only if you assume int never overflows. Requiring operator++
to overflow will prohibit this optimization.
- Re: signed is undefined and has been since 1992 ... Gabriel Dos Reis
- Re: signed is undefined and has been since 1... Robert Dewar
- Re: signed is undefined and has been sin... Gabriel Dos Reis
- Re: signed is undefined and has bee... Robert Dewar
- Re: signed is undefined and has... Gabriel Dos Reis
- Re: signed is undefined and has... Robert Dewar
- Re: signed is undefined and has been sin... Joe Buck
- Re: signed is undefined and has bee... Olivier Galibert
- Re: signed is undefined and has bee... Robert Dewar
- RE: signed is undefined and has been since 1992 (in GCC) Dave Korn
- Re: signed is undefined and has been since 1992 (in GCC) Michael Veksler
- Re: signed is undefined and has been since 1992 (in GCC) Robert Dewar
- Re: signed is undefined and has been since 1992 (in ... Gabriel Dos Reis
- Re: signed is undefined and has been since 1992 ... Robert Dewar
- Re: signed is undefined and has been since 1... Gabriel Dos Reis
- Re: signed is undefined and has been sin... Robert Dewar
- Re: signed is undefined and has bee... Gabriel Dos Reis
- Re: signed is undefined and has... Robert Dewar
- Re: signed is undefined and has... Gabriel Dos Reis
- Re: signed is undefined and has... Paul Koning
- Re: signed is undefined and has... Andreas Schwab
