Inline Specifier

The inline function specifier is a recommendation that the compiler replace calls to the specified function with the function’s body, if possible.

The following is an example of a function which has been made a candidate for inlining.

inline int combine(int x, int y) {
  return 2*x-y;
}

All function calls to a function that was inlined by the compiler will be encoded as if the call was replaced with the body of the called function. This is performed at the assembly code level. Inlining will only take place if the assembly optimizers are enabled, which occurs at the higher optimization levels and which precludes this action if you are running an unlicensed compiler. The function itself might still be encoded normally by the compiler even if it is inlined.

If inlining takes place, this will increase the program’s execution speed, since the call/return sequences associated with the call will be eliminated. It will also reduce the hardware stack usage as no call instruction is executed; however, this stack-size reduction is not reflected in the call graphs, as these graphs are generated before inlining takes place.

Code size can be reduced if the assembly code associated with the body of the inlined function is very small, but code size can increase if the body of the inlined function is larger than the call/return sequence it replaces. You should only consider this specifier for functions which generate small amounts of assembly code. Note that the amount of C code in the body of a function is not a good indicator of the size of the assembly code that it generates (see How Can I Tell How Big a Function Is?).

A function containing in-line assembly will not be inlined. Some generated assembly code sequences will also prevent inlining of a function. A warning will be generated if the inline function references static objects (to comply with the C Standard) or is not inlined successfully. Your code should not make any assumptions about whether inlining took place.

This specifier performs the same task as the #pragma inline directive (see ). Note that the optimizers can also implicitly inline small called-only-once routines (see The #pragma Intrinsic DirectiveAssembly-Level Optimizations).

If the xc8-cc flag -Wpedantic is used, the inline keyword becomes unavailable, but you can use the __inline keyword.