c++ - What happens when you bit shift beyond the end of a variable? -


if have variable (on stack) , left or right bit shift beyond end happens?

i.e.

byte x = 1; x >> n; 

what if x pointer memory cast byte , same thing?

byte* x = obtain pointer somewhere; *x = 1; *x >> n; 

it not (necessarily) become zero. behavior undefined (c99 §6.5.7, "bitwise shift operators"):

if value of right operand negative or greater or equal width of promoted left operand, behavior undefined.

(c++0x §5.8, "shift operators"):

the behavior undefined if right operand negative, or greater or equal length in bits of promoted left operand.

the storage of value being shifted has no effect on of this.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -