C Programming: difference between ++i and i=i+1 from an assembler point of view?

后端 未结 6 499
予麋鹿
予麋鹿 2021-02-05 11:53

This was an interview question. I said they were the same, but this was adjudged an incorrect response. From the assembler point of view, is there any imaginable difference? I h

6条回答
  •  抹茶落季
    2021-02-05 12:15

    You are probably right. A naive compiler might do:

    ++i to inc [ax]
    

    and

    i = i + 1 to add [ax], 1
    

    but any half sensible compiler will just optimize adding 1 to the first version.

    This all assumes the relevant architecture has inc and add instructions (like x86 does).

提交回复
热议问题