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

后端 未结 6 513
予麋鹿
予麋鹿 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:28

    the context is the main thing here because on a optimized release build the compiler will optimize away the i++ if its available to a simple [inc eax]. whereas something like int some_int = i++ would need to store the i value in some_int FIRST and only then increment i.

提交回复
热议问题