pre-increment versus post-increment
Just a note: compiler optimization is often disabled in debug mode. Unless you particularly enjoy having your nice interactive game turn into a slideshow when you're trying to fix a bug using a debuggable build, you should get into the habit of the "small" pre-optimizations that result in less work for the compiler and don't require sophisticated optimization passes to make efficient.
Of course, _profile your code_ rather than blindly applying advice off the Internet...
Of course, _profile your code_ rather than blindly applying advice off the Internet...
IIRC VS elided the integer temporary in for loop in debug last I looked at it. I could look again, but I'm in lazy mode right now. (Also, it won't do that for non-integer types (I hope) so don't rely on it.)
Accidentally hit down vote instead of up vote, apologies.I use pre because it's algorithmically simpler.
...
I never use either pre- or post-increment as side effect in a computation, I always write it as a separate statement.
Then immediately, the entire "pre or post"? problem disappears (I always use post, out of habit, and better looks), and the compiler is free to optimize however it likes.
I never checked what the compiler actually does there.
Accidentally hit down vote instead of up vote, apologies.I use pre because it's algorithmically simpler.
...
Up-voted to cancel out your mis-vote.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement