>>2 ++i is on very rare occasions faster in a certain retarded C-derived language. FTFY.
Name:
newfriend2011-09-11 22:29
Is that retarded C-derived language named Jave?
Name:
Anonymous2011-09-11 22:31
>>2
Those are known as non-conforming implmentations you idiot. Of course the only way you would have known something like this is if you would have read one of the ANSI/ISO C standards instead googling shit.
Name:
Anonymous2011-09-11 22:31
i += 1 is the only way.
Name:
Anonymous2011-09-11 22:52
++i; is faster than i++; if your compiler is retarded.
The compiler, regardless of whether it's C or C++, will optimize post-decrementation (i++) to pre-decrementation (++i) if the return value is not used IFF the type of i is integral (for example an int or a non-void pointer).
However, C++ iterators are often not integral or pointer types. They have their own over-ridden operator++ functions. If those operators are not inline functions, or if inlining is disabled in the case of debug-builds, the compiler can't make the above optimization. In which case, pre-increment on iterator variables is always faster because no temporary is created. This is why the experts, when programming in C++, choose to use pre-increment.
Using it here or there might seem as premature optimization, but it's one of those things that have no associated cost to the programmer to do, and when done consistently throughout your code-base can help make a small difference, especially in debug builds (nothing worse than trying to debug a program that is extremely fucking slow in debug mode).