This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

right/left shifts with (width of type)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]