pre-increment versus post-increment

Started by
13 comments, last by Lactose 7 years, 3 months ago
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...

Sean Middleditch – Game Systems Engineer – Join my team!

Advertisement

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.)

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

I use pre because it's algorithmically simpler.
...

Accidentally hit down vote instead of up vote, apologies.

- Jason Astle-Adams

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.

I use pre because it's algorithmically simpler.
...

Accidentally hit down vote instead of up vote, apologies.

Up-voted to cancel out your mis-vote.

Hello to all my stalkers.

This topic is closed to new replies.

Advertisement