Function Inlining by GCC
Inline function is an optimisation technique used by the GCC compiler. The compiler will try to insert the complete body of the function wherever the function is used. This will eliminate the time overhead when the function is called each time. The details about this insertion can be viwed by looking at the machine code.
Consider the following example:
We can get the assembly code by doing the compilation upto second phase.
On viewing the assembly code we could see the function call, sqr.
In this, the value 10 is pushed to to the register esp. On calling the function the esp address value will be decremented by 4 and the control jumps to the function. The square is evaluated there and stored in the register eax.
The method will create a time overhead of calling the function. Using the optimization option -O3 of gcc we can do the function inlining.
After the optimisation if we look at the assembly code, we can see that there is no function call. In that place we can see the value obtained by evaluating the function.
This example is an example of the extreme case of function inlining. In this the compiler knows that the function sqr will take a parameter which in this case is a constant. There is no need of evaluating the function value at runtime. The compiler evaluates the function at compile time itself and use that value at runtime eliminating the overhead of calling function at runtime. If the parameter was a variable, the compiler would have inserted the function body there.
The limit on the number of lines strictly depend upon the gcc heuristics.