Bleichenbacher's Ghost

Hey man, computer security is hard.

++i versus i++

Posted on — Jul 6, 2020;   Reading Time — 1 minute

The Google C++ Style Guide says,

The figure shows the text from
The Google C++ Style Guide on Preincrement and Predecrement

I took their word for it. But, when I mentioned this to a friend of mine who works on compilers, he didn’t believe it for a second. He claimed that today’s compilers were smarter than this: that is, if your code doesn’t need the result of the postfix increment/decrement, then the compiler will optimize out the copy. Then I spent some time playing around with the Compiler Explorer, even stooping as low as to use Clang 3.7.0, to eek out some performance. But, alas, I failed. There doesn’t seem to be any reason to prefer ++i to i++ in a situation where either can be used.