There is also one more explanation of this:
By declaring a function inline
,
you can direct compiler to integrate that function's code into the code for its callers.
This makes execution faster by eliminating the function-call overhead;
in addition, if any of the actual argument values are constant, their known values may permit simplifications at compile time so that not all of the inline function's code needs to be included.
The effect on code size is less predictable; object code may be larger or smaller with function inline
, depending on the particular case.
Inline
functions is an optimization and it really “works” only in optimizing compilation. If you don't use -O, no function is really inline
.
and For static inline function
:
When a function is both inline
and static
,
if all calls to the function are integrated into the caller, and the function's address is never used, then the function's own assembler code is never referenced.
In this case, compiler
does not actually output assembler code for the function, unless you specify the option -fkeep-inline-functions.
Some calls cannot be integrated for various reasons (in particular, calls that precede the function's definition cannot be integrated, and neither can recursive calls within the definition).
If there is a non integrated call, then the function is compiled to assembler code as usual. The function must also be compiled as usual if the program refers to its address, because that can't be inlined
.