I guess this was all said already, but:
Quote:Original post by swiftcoder
Quote:Original post by DevFred
Furthermore, i++ can NEVER be faster than ++i. I ALWAYS write ++i.
That isn't entirely true - if i is an integral type, there is really no reason why the compiler cannot compile both expressions to the identical assembly. For aggregate types you are of course correct.
Er, I have to wonder how quickly you can spot the bug in the following code, then:
int foo[10];for (int i = 0; i <= 10; ++i) { foo = 42; }
:) Faster != at least as fast.
Modern C++ developers write ++i by instinct. The only reason not to do so is because i++ yields correct logic and ++i doesn't; and in these cases, you should almost certainly prefer something else entirely.