Here are my comments to the ++i vs i++ topic:
- in C, these two are totally equivalent in that for loop context.
- I know at least one compiler of a C-like language that does generate inefficient code for i++ even in for loop context, and even warns about every single use of post-increment no matter if sensible or not
- in C++, they are very non-equivalent, given that they call different functions:
++i calls
itype itype::operator++() { increment(*this); return this; }
i++ calls
itype itype::operator++(int) { itype icopy(*this); increment(*this); return icopy; }
If the operators or copy constructor cannot be called inline, the compiler has no way to optimize out the internal temporary created by the post-increment!
Personally, i++ (postincrement) is the odd one to me, and it should used only if it is sensible. Typical sensible use of it is code like
line = 0; a[line++] = "first line"; a[line++] = "second line"; while(...) a[line++] = "more lines";