Possible Duplicate:
Is there a performance difference between i++ and ++i in C++?
I understand that:
i++;
Is supposed to take more instructions than
++i;
Because it's generating an intermediate result that you don't need to use, so people put "++i" on lines of code that have no use for the intermediate result.
However, compilers are really smart, and they can tell if a result is being used or not. They can tell all kinds of things. But they aren't magic
So I am curious - on modern compilers does picking one way over the other actually matter or will it simply compile to the same machine code regardless?
It does not matter when using it on an int
. However, when using iterators or other objects that overload operator++
, it might still make a difference.