Hi, like the title says I'm facing very weird behavior when trying to manipulate some bits. This happens only in VS 2015, in other places everything works fine ( getting result 00000000 00000000 00000000 00000000)
Why is line 9 giving me this behaviour in VS 2015?
main.cpp:8:25: warning: shift count >= width of type [-Wshift-count-overflow]
print_bits((~0) << 32); //given this I get 00000000 00000000 00000000 00000000
^ ~~
1 2 3
main.cpp:8:28: warning: left shift count >= width of type [-Wshift-count-overflow]
print_bits((~0) << 32); //given this I get 00000000 00000000 00000000 00000000
^
since the behavior is undefined, there is absolutely no guarantee for anything the program does in this case.
Looking at the ASM from my compiler the (~0) << 32 is baked in, whereas the (~0) << n gets computed at runtime. (the baked in version treats the computation differently, probably because of what Cubbi mentioned)