Keil Logo

__inline: Function in-lining

The CARM Compiler supports function inlining (using the __inline function attribute) and cross-module function inlining (using the extern keyword).

<[>extern<]> __inline <[> type <]> funcname (<[> args <]>)


extern enables cross-module function in-lining and makes the function available in other modules.
__inline specifies that the function is an inline function.
type is the type of the value returned from the function. If no type is specified, int is assumed.
funcname is the name of the function.
args is the argument list for the function.

Function inlining replaces a call to a function with the body of the function. This speeds up program execution by eliminating the call/return code, the code required to pass parameters, and the code required for return values. In addition, the compiler optimizes expanded inline functions with the rest of the code.

Cross-module function inlining replaces calls to inline functions defined in other source files. Use the extern keyword as shown above to declare cross-module inline functions.

All function inlining is actually performed by linker (not by the compiler) after function parameters are calculated. Refer to the INLINE directive in the LARM Linker User's Manual for more information.


  • Using function inlining indiscriminately can result in much larger code size and no increase in execution speed. 

The CARM Compiler may reduce the size of the code generated when you use inline functions if some of the inline function arguments are constant expressions.

__inline void PortOut (
  unsigned int io,
  unsigned int pos,
  int state)
switch (io)
  case 0:
    if (state == 0)  IOCLR0 |= pos;
    else             IOSET0 |= pos;

  case 1:
    if (state == 0)  IOCLR1 |= pos;
    else             IOSET1 |= pos;

In such cases, the compiler only inserts the relevant function code. For instance,

PortOut (1, 0x40, 1);


IOSET1 |= 0x40;

Other code in the PortOut function is eliminated since the io and state parameters are constant.

Some restrictions apply to the __inline attribute. As such, function inlining is disabled for:

  • the main function or functions with the __irq, __swi, __task, __fiq, or __ram attributes.
  • recursive functions that are called either directly (within the same function) or indirectly (via other functions).
  • functions with variable-length argument lists (... parameter) or functions with more than 32 parameters.
  • functions called indirectly via a function pointer (address of a function is taken).
  • functions that return a struct or union or have a parameter of the type struct or union.
  • functions that are compiled with a different CPU mode (ARM or Thumb) than the calling function.
  • when a function argument calls another function.
  • the number of arguments passed to the inline function do not match the number of parameters in the function declaration.


  • Functions declared with the __inline attribute (but without the extern keyword) are static may not be called from other modules.
  • Functions declared with the extern and __inline attributes may be called from other modules. The CARM Compiler performs cross module function in-lining.
  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.