Keil™, An ARM® Company

Technical Support

C166: __INLINE GENERATES CALL OR WARNING #197


Information in this article applies to:

  • C166 Version 5

QUESTION

The __inline keyword does not seem to inline the code in all cases. It looks like code for a subroutine generated and called via CALLS or CALLA. Is this a bug?

ANSWER

According to ANSI-C standard '__inline' is implementation defined. The C166 is not always able to inline a function, or inlining is not done to avoid potential run-time problems.

The C166 generally ignores the attribute __inline if the function:

  • returns a struct or union.
  • has a struct or union parameter.
  • is not reentrant.
  • is called main.
  • uses #pragma DISABLE to disable interrupts.
  • is declared with the using bankname attribute.
  • calls other functions (except functions from the standard library).
  • is located in a source file, where the SRC directive is used to generate an assembler listing.

Function in-lining is performed on expression statement boundary where the right side operator is a function call:

z = iFunc (z1, z2)          // in-lined:     first operation is function call
z = iFunc (z1, z2) * 11     // not in-lined: first operation is multiplication
z = iFunc (z1, z2) + 2;     // not in-lined: first operation is addition

Expressions of a 'for' statement are never in-lined, for example:

for (z = iFunc (z1, z2) ; z != 0 ; )  {  // call to iFunc never in-lined
           ...
}

An __inline function with no calls (Leaf function) or calls to other Leaf functions is in-lined as long as the above rules are fulfilled.

static __inline int yFunc (int n)  {
  return (n + 10);
}

static int zFunc (int n)  {
  return (n + 10);
}

static __inline int iFunc (int i, int y)  {
  i += y;
  i += yFunc (y);      // Note: i += yFunc * zFunc (i): not in-lined
  i *= zFunc (i);
  return (i);
}

static int z, z1, z2;

void main (void)  aaaa{
  z = iFunc (z1, z2);           // in-lined
  z = z2 + iFunc (z1, z2);      // not in-lined
  z = iFunc (z1, z2) * 11;      // not in-lined
}

MORE INFORMATION

  • C166 User's Guide

Last Reviewed: Saturday, May 01, 2004


Did this article provide the answer you needed?
 
Yes
No
Not Sure