Keil Logo

Inline functions

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.

Note:

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_0612_00_en
Copyright © 2014–2019 Arm Limited or its affiliates. All rights reserved. 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.