Benefits of inline functions in C++?

后端 未结 14 1547
终归单人心
终归单人心 2020-11-22 05:30

What is the advantages/disadvantages of using inline functions in C++? I see that it only increases performance for the code that the compiler outputs, but with today\'s opt

14条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 05:55

    Inline function is the optimization technique used by the compilers. One can simply prepend inline keyword to function prototype to make a function inline. Inline function instruct compiler to insert complete body of the function wherever that function got used in code.

    Advantages :-

    1. It does not require function calling overhead.

    2. It also save overhead of variables push/pop on the stack, while function calling.

    3. It also save overhead of return call from a function.

    4. It increases locality of reference by utilizing instruction cache.

    5. After in-lining compiler can also apply intra-procedural optimization if specified. This is the most important one, in this way compiler can now focus on dead code elimination, can give more stress on branch prediction, induction variable elimination etc..

    To check more about it one can follow this link http://tajendrasengar.blogspot.com/2010/03/what-is-inline-function-in-cc.html

提交回复
热议问题