Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 5
    Which optimization level did you specify with compiling? Looking at code built with -O0 is kind of pointless, at least if you're going to scrutinize its efficiency. Commented Aug 17, 2015 at 13:02
  • I'm less concerned with efficiency, just curious when this extra mov would ever be useful. On a side note, optimizing with -02 removes the redundant operation. Commented Aug 17, 2015 at 13:12
  • 2
    It is part of the direct meaning of b=++a. It is effectively the same as b=(a+=1); so you compute a+1 and store that into a and then copy from a to b. An unoptimized compile is not supposed to notice that the value just stored into a is still in eax, so you don't need to read it back from a when copying a to b. An unoptimized compile forgets the register contents after each step. Commented Aug 17, 2015 at 13:19
  • 1
    Also notice that the first three instructions do the ++a and the final 2 do the b = a (where a already has the incremented value). Due to no optimization, the compiler didn't eliminate the reload of eax. Commented Aug 17, 2015 at 13:20