11.5 Inline functions

  ----------------------

 

      'Inline' functions can be dynamic functions which are used as macros,

  but unlike macros, these functions, when you are optimizing for speed, are

  automatically inserted into the code, and when you are optimizing for size,

  are called as dynamic functions.

 

      Sometimes, however, it is necessary when optimizing for code size for

  the functions to be inserted into the code and not called. This can be done

  using the directive '#inline TRUE'. This same directive (as '#inline

  FALSE') can cause functions to be called instead of inserted when

  optimizing for speed.

 

      Note that the status of '#inline' automatically changes when the

  optimization condition changes. When you are optimizing for speed, #inline

  is TRUE, but when you change to optimization for code size, it is set to

  FALSE. This directive should therefore be applied only after changing the

  optimization condition.

 

      Directives which change the optimization conditions #codesize and

  #speed, along with #inline are declared inside a function only on the

  remaining part of the function, i. e., they are local directives. In order

  for the changes to be global, these directives must be declared outside of

  the body of the function.

 

      To define an inline function, the first string with the function name

  must contain instead of ':', which indicates a dynamic function, the

  keyword 'inline'. For example:

 

  inline int fastcall abs(AX)

  {

      IF ( int AX < 0 ) -AX ;

  }

 

 

    11.5.1 Another use of 'inline'

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

        The keyword 'inline' has another use in functions. If this word is

    found before the start of a function block, no stack frame is created for

    this function and no 'ret' is generated to close the function. For

    example:

 

    void PROC ()

    inline

    {

      ...

    }

 

        Such functions cannot contain local variables. If this is a register

    function (of type 'fastcall') there is no problem in transferring its

    parameters. If, however, it is a stack function, parameters can be

    transferred to this function but these functions cannot be called via

    their names. This is because a stack frame is not formed in these

    functions.

 

        For example:

 

    void proc (int par1, par2)

    inline

    {

      AX=par1; /* the compiler addresses with parameter 'par1' through

              register BP. But since frame of stack was not created,

              when performing this code a program will work not

              correctly. */

      ...

    }

 

        The compiler addresses with parameter 'par1' via register BP. But

    since no stack frame was created, the program will not work properly when

    executing this code.

 

        On encountering such a function definition, the compiler will warn

    that local and formal parameters cannot be used in such functions.