Inline functions vs Preprocessor macros

后端 未结 14 2298
一个人的身影
一个人的身影 2020-11-22 12:37

How does an inline function differ from a preprocessor macro?

14条回答
  •  粉色の甜心
    2020-11-22 13:35

    An inline function will maintain value semantics, whereas a preprocessor macro just copies the syntax. You can get very subtle bugs with a preprocessor macro if you use the argument multiple times - for example if the argument contains mutation like "i++" having that execute twice is quite a surprise. An inline function will not have this problem.

提交回复
热议问题