| |||
| Home > Coding Practices > Function inlining | |||
Function inlining offers a trade-off between code size and performance. By default, the compiler decides for itself whether to inline code or not. As a general rule, the compiler makes sensible decisions about inlining with a view to producing code of minimal size. This is because code size for embedded systems is of fundamental importance.
In most circumstances, the decision to inline a particular function is best left to the compiler. However, you can give the compiler a hint that a function is required to be inlined by using the appropriate inline keyword. The compiler also offers a range of other facilities for modifying its behavior with respect to inlining. There are several factors you must take into account when deciding whether to use these facilities, or more generally, whether to inline a function at all.
Functions that are qualified with __inline, inline,
or __forceinline are called inline functions. In
C++, member functions that are defined inside a class, struct, or
union, are also inline functions.
Be aware that profile guided optimizations can affect function inlining. See --profile=filename in the Compiler Reference Guide.