cpp-best-practices/cppbestpractices

Additional motivation i++ vs ++i

jorenheit opened this issue · 3 comments

Very glad to hear that pre-increment should be preferred. However, your reasons are easily debunked in modern times where compilers will optimize both versions to the same machine level instructions. However, this argument breaks as soon as more complicated types are used: iterators. Your example uses plain old ints, but it would be clearer if you elaborated a little by using (user-defined) classes that overload ++.

Even I would not recommend to write your code in a way that relies on optimizations that a compiler should do, I agree that some additional information to this would improve the document.

I totally agree, yet this is a counter argument I have come across many times. Thanks for your response. I appreciate this initiative!

If either of you has a good example or a good way to re-word this section, please make a pull request for it.