On Wed, 26 May 2004 22:42:52 +0200, "Heinz Ozwirk" <>
wrote in comp.lang.c++:
> "GGG" schrieb
>
> > uint32_t x = 5;
> > uint32_t y = x << 32;
> > uint32_t z = x << 32;
> >
> > In the above example y and z are both still 5. Why is this?
> >
> > Now I understand doing a shift like this seems silly, but in this code
> > sometimes the resulting shift validly turns out to be exactly the
> > number of bits in that data type, and expects the result to be 0.
>
> It doesn't matter what you are expecting. The behaviour of shifts defined
> only if the value of the right operand is less than the number of bits in
> the left operand. So shifting a 32-bit value by 32 or more is undefined or
> at least not specified in the standard and each compiler may do whatever
> it thinks to be best.
>
> Heinz
First, please find the setting in your news posting software where you
tell it to insert line breaks at some interval in the range of 65 to
89 characters. Thank you.
Next, you are partially correct. The value of the right operand must
not only be less than the width in bits of the (promoted) left
operand, it must also be greater than or equal to 0.
Both a negative right operand, or one as large or larger than the
number of bits in the promoted left operand cause undefined behavior.
--
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++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html