Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline Functions - Automatic inline

When a short function is defined inside a class declaration, it is automatically made into an inline function.

My questions are,

  1. How short the function should be for automatically in-lining ? Is there any line-limit for that?
  2. Is there any way to know that a function is automatically in-lined ?
like image 643
Kaushik Avatar asked Sep 10 '13 18:09

Kaushik


1 Answers

  1. How short the function should be for automatically in-lining ? Is there any line-limit for that?

There is no hard limit (or more precisely yes, we can find upper limit on a given system but you won't find it specified anywhere). The compiler tries to predict what the advantages of this process given particular circumstances might be. If the compiler decides that inlining the function will make the code slower, or unacceptably larger, it will not inline it. It won't do it also if it simply cannot do it because of a syntactical dependency, such as other code using a function pointer for callbacks, or exporting the function externally as in a dynamic/static code library. Remember also that marking function inline is only expressing a wish, compiler is not obliged to do this. In C, any function with internal linkage can be inlined, but a function with external linkage is subject to restriction.

  1. Is there any way to know that a function is automatically in-lined ?

You can disassemble the binary and you will see if there is an call to a function or if it is in line.

Do inline functions improve performance?

Inline Functions

like image 136
4pie0 Avatar answered Oct 20 '22 21:10

4pie0