Inline function v. Macro in C — What's the Overhead (Memory/Speed)?

后端 未结 9 1254
太阳男子
太阳男子 2020-12-02 13:18

I searched Stack Overflow for the pros/cons of function-like macros v. inline functions.

I found the following discussion: Pros and Cons of Different macro function

9条回答
  •  臣服心动
    2020-12-02 13:47

    The best way to answer your question is to benchmark both approaches to see which is actually faster in your application, using your test data. Predictions about performance are notoriously unreliable except at the coarsest levels.

    That said, I would expect there to be no significant difference between a macro and a truly inlined function call. In both cases, you should end up with the same assembly code under the hood.

提交回复
热议问题