Inline expansion

The inline replacement is in programming a method for increasing the execution speed by eliminating unnecessary calls to subprograms are avoided. Instead, the code of the function at the points where it is called is copied by the compiler and can be also fully taken into account in the optimization.

For example ( in the programming language C )

The following source code ...

Inline int das_Quadrat_von (int x ) {       return x * x;    }    void f (int j ) {       int k = j das_Quadrat_von ( j) 1;       int m = 2 * das_Quadrat_von (k ) 5;       int p = das_Quadrat_von (j 1);       int q = das_Quadrat_von ( j 2 );       / / ...    } So ... is translated by the compiler that the function is not called, but the function definition is inserted directly ( replacing highlighted):

Void f (int j)    {       int k = j ( j * j) 1;       int m = 2 * (k * k) 5;       p = int (j 1) * (j 1);       j;       int q = ( j 2 ) * ( j 2 );       / / ...    } Inline substitution therefore met in C a purpose similar to a macro function, but also offers the security of a static type checking as functions. You must be explicitly declared and can be used for classes of independent, as well as member functions (methods). In the internals of the compiler macros and inline substitutions are not comparable.

It is for the compiler but not possible for any function of any complexity, also perform the desired substitution by the programmer. Then the normal function call is maintained. Rather, this is inline in the example as a recommendation to the compiler to see that he did not have to pursue. Especially in C , there are exceptional cases also compiler - specific stronger variants of inline ( such as __ forceinline it) which, however, may come at the expense of portability. Without such variants, the inline attribute is ignored by most modern compilers, at least at high optimization levels.

Some compilers can also autonomously for inline replacement identify and expand appropriate functions in the optimization phase. In the programming language Eiffel about just this automatic inline substitution is provided.

  • Programming tool
  • C