6.3 Inline functions

Inline functions offer a trade-off between code size and performance. By default, the compiler decides 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 to restrict code size, through the use of -Oz or -Os, the compiler makes sensible decisions about inlining and aims 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 short functions.


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, because it is only acting as a suggestion.
  • Compile your program using the GNU C90 dialect, using the -std=gnu90 option.
Non-ConfidentialPDF file icon PDF version100067_0609_00_en
Copyright © 2014–2017 Arm Limited (or its affiliates). All rights reserved.