Inline function prototype vs regular declaration vs prototype

前端 未结 4 991
别那么骄傲
别那么骄傲 2020-12-21 09:02

What\'s the difference between inline function and then main like so:

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

int main( )
{
    cu         


        
4条回答
  •  情歌与酒
    2020-12-21 09:14

    Performance wise, they are all the same since inline is just a hint for the compiler. If the separation of declaration/definition is used and the definition is on a different translation unit, then it will be harder for the compiler to inline it (but there are implementations that do so).

    A difference with making a function inline or not is that the linker will not complain if it sees the same inline definition for a function more than once.

提交回复
热议问题