error with define macro definition

后端 未结 3 1754
执念已碎
执念已碎 2020-12-21 14:40

when i am using #define function,I observe something bizarre. In the below code if I gave i value as \'10\' from input i

相关标签:
3条回答
  • 2020-12-21 15:38

    Macro's have subtleties. What your macro does is: Double(++i) -> ++i*++i

    in your case 11*12 or 12*11

    0 讨论(0)
  • 2020-12-21 15:42

    What you have is undefined behaviour.

    You Double(++i) is changed to ++i * ++i, when you compile you code.

    0 讨论(0)
  • 2020-12-21 15:44

    Double(++i) will expand to ++i * ++i. In this expression, i is modified twice without an intervening sequence point, which is undefined behavior.

    Read: So, what's wrong with using macros?

    0 讨论(0)
提交回复
热议问题