Right-shift bug in egcs-2.91.66
Dale Johannesen
dalej@apple.com
Fri May 11 10:24:00 GMT 2001
On Friday, May 11, 2001, at 10:06 AM, Timur Tabi wrote:
> Now, I received a reply that says that "test >> 32" is undefined:
>
> Per "The C Programming Language 2nd edition" appendix A7.8
> Shift operators
> "The result is undefined if the right operand is negative, or greater
> than or equal to the number of bits in the left expression's type."
>
> Well, this is stupid. Dividing by zero is undefined because
> mathematically
> there are an infinite number of answers. But the above can easily be
> defined.
> Shifting by equal or more than the number of bits in the operand
> results in zero.
> It's very simple.
>
> (IMHO, shifting by a negative number is equal to shifting in the
> opposite
> direction by the positive, but I can understand why this might not be
> implemented).
If you have a problem with the language definition, you should take it
up with the C standards committee, not with us. But to get an idea what
they might say, consider what the generated code for (X>>Y) would look
like under your proposal.
More information about the Gcc-bugs
mailing list