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

后端 未结 9 1256
太阳男子
太阳男子 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:40

    It's the calls to pow() you want to eliminate. This function takes general floating point exponents and is inefficient for raising to integral exponents. Replacing these calls with e.g.

    inline double cube(double x)
    {
        return x * x * x;
    }
    

    is the only thing which will make a significant difference to your performance here.

提交回复
热议问题