This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Re: c/7284: incorrectly simplifies leftshift followed by signed power-of-2 division
- From: "Al Grant" <AlGrant at myrealbox dot com>
- To: falk dot hueffner at student dot uni-tuebingen dot de
- Cc: nathan at gcc dot gnu dot org,algrant at acm dot org,gcc-bugs at gcc dot gnu dot org,gcc-prs at gcc dot gnu dot org,nobody at gcc dot gnu dot org,gcc-gnats at gcc dot gnu dot org
- Date: Fri, 12 Jul 2002 16:50:21 +0000
- Subject: Re: Re: c/7284: incorrectly simplifies leftshift followed by signed power-of-2 division
>Right, I just assumed it to be very unlikely that this was changed to
>be undefined in C99.
So did I, otherwise I would have checked it!
>I don't have the C89 standard; could you perhaps
>cite the passage that shows this was defined >behaviour in C89?
3.3.7 (something else in ISO, maybe 6.3.7)
The result of E1 << E2 is E1 left-shifted E2 bit
positions; vacated bits are filled with zeros.
It then goes on to say "If E1 has an unsigned type..." and notes that it is equivalent to a multiplication.
For signed types it says nothing more.
Now if signed left-shift is defined at all, in terms
of the representation, I don't see there's any lack of definition in "0x00000080 left-shifted 24 bit positions", it is clearly 0x80000000 (of the same type). So it's defined unless the standard says otherwise, which only C99 seems to.
There's no reason given to treat it specially if it happens to represent a negative signed number. This is not a case of an ideal signed arithmetic operation producing some result in the ideal integers that cannot be represented in the particular signed type, so the undefinedness in that case doesn't apply here.