This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
right/left shifts with (width of type)
- To: egcs-bugs at cygnus dot com (egcsbugs)
- Subject: right/left shifts with (width of type)
- From: Stefan Meixner <Stefan dot Meixner at emskopp dot a dot shuttle dot de>
- Date: Thu, 2 Jul 1998 13:59:08 +0200 (CEST)
Hi,
right now I will not call it a bug, but gcc/egcs
practise with right/left shifts with counts equal
to the width of the type is at least not protable
(at least on a i486-pc-linux-gnulibc1 where I tested it).
I would expect the following expression to hold
for both << and >> operators
unsigned long u = ~0;
if ( (u << (sizeof(unsigned long)*CHAR_BIT)) == 0 )
printf("GOOD");
else
printf("BAD");
At least this is the behavior I would expect and I get from
the other compilers I tested.
I know that this maybe implementation defined. But shifting
any unsigned long by count=width, the result should be zero.
Am I wrong?
Thanks for listening!
Stefan