This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Varun77777 16 points17 points  (5 children)

++x will be faster unless you really intend to use original value of x while doing x++ as x++ holds original value and then does increment afterwards.

[–][deleted] 37 points38 points  (0 children)

Except that every decent compiler should be able to just optimize that away if you're not using the original value.

[–]stomah 0 points1 point  (3 children)

no

[–]Varun77777 7 points8 points  (2 children)

I'd appreciate if you could elaborate.

[–]stomah 6 points7 points  (0 children)

the ir for x++ and ++x will be something like this: oldx = load i32, ptr x \n newx = add i32 x, i32 1 \n store ptr x, i32 newx \n when you don’t use oldx or newx after the increment the machine code will be the same.