5.2 Inline functions

Inline functions offer a trade-off between code size and performance. By default, the compiler decides for itself whether to inline functions.

With regards to optimization, by default the compiler optimizes for performance with respect to time. If the compiler decides to inline a function, it makes sure to avoid large code growth. When compiling with respect to restraining code size, through use of -Oz or -Os, the compiler makes sensible decisions about inlining, aiming to keep code size to a minimum.
In most circumstances, the decision to inline a particular function is best left to the compiler. Qualifying a function with the __inline__ or inline keywords suggests to the compiler that it inlines that function, but the final decision rests with the compiler. Qualifying a function with __attribute((always_inline)) forces the compiler to inline the function.
The linker is able to apply some degree of function inlining to functions that are very short.


The default semantic rules for C-source code follow C99 rules. For inlining, it means that when you suggest a function is inlined, the compiler expects to find another, non-qualified, version of the function elsewhere in the code, to use when it decides not to inline. If the compiler cannot find the non-qualified version, it fails with the following error:
"Error: L6218E: Undefined symbol <symbol> (referred from <file>)".
To avoid this problem, there are several options:
  • Provide an equivalent, non-qualified version of the function.
  • Change the qualifier to static inline.
  • Remove the inline keyword, since it is only acting as a suggestion.
  • Compile your program using the GNU C90 dialect, using the -std=gnu90 option.
Related reference
2.8 __inline
1.47 -std
3.2 __attribute__((always_inline)) function attribute
Non-ConfidentialPDF file icon PDF versionARM DUI0774E
Copyright © 2014-2016 ARM. All rights reserved.