Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

GCC increment Optimization

Name: Anonymous 2009-05-28 17:25

Does anyone know if GCC v4.x optimizes automatically the incr i++; to ++i; ?

Name: Anonymous 2009-05-29 16:44

They are not the same, even when used as an expression-instruction:

++i; increments the value of i first and then puts it on the stack, to be immediately after cleared out (since the value isn't used)
i++; first puts 'i' on the stack, duplicates it, increments one 'i' and puts it back to 'i', leaving the unchanged value on the stack to be used if needed (cleared out after, as it isn't used)

to summarize, 'i++' uses one duplicate more than '++i'

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List