Does the C++ compiler optimize the multiply by two operation x*2
to a bitshift operation x<<1
?
I would love to believe that yes.
Does the C++ compiler optimize the multiply by two operation x*2
to a bitshift operation x<<1
?
I would love to believe that yes.
Unless something is specified in a languages standard you'll never get a guaranteed answer to such a question. When in doubt have your compiler spit out assemble code and check. That's going to be the only way to really know.