On Sat, 27 Sep 2003 12:45:04 -0700, Davis King <>
wrote in comp.lang.c++:
> I just discovered that sometimes on some compilers it is true that
> (variable >> 32) == variable where variable is an unsigned long and on
> these platforms an unsigned long is 32 bits. Is bit shifting a
> variable in the manner undefined by the standard or is this just a bug
> in the compiler?
>
>
>
>
> examples:
> in borland 5.5.1 the following code prints 1, I would expect it to be 0
> unsigned long low = 1;
> low >>= 32;
> cout << low;
>
> I also found a similar problem in visual studio but weather or not
> (low>>32) == low or 0 is apparently dependent upon what (seeming
> independent) statements precede the shift.
If the shift count for an integer type is negative or greater than or
equal to the number of bits, the result is undefined. The compiler is
absolutely correct.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
ftp://snurse-l.org/pub/acllc-c++/faq