Procedures that are declared inline are copied to the places where they are called. This has the
effect that there is no actual procedure call, the code of the procedure is just copied to
where the procedure is needed, this results in faster execution speed if the function
or procedure is used a lot. It is obvious that inlining large functions does not make
sense.
By default, inline procedures are not allowed. Inline code must be enabled using the
command-line switch -Si or {$inline on} directive.
Remark
- inline is only a hint for the compiler. This does not automatically mean that all
calls are inlined; sometimes the compiler may decide that a function simply cannot be
inlined, or that a particular call to the function cannot be inlined. If so, the compiler
will emit a warning.
- In old versions of Free Pascal, inline code was not exported from a unit. This meant
that when calling an inline procedure from another unit, a normal procedure call will
be performed. Only inside units, Inline procedures are really inlined. As of version
2.0.2, inline works across units.
- Recursive inline functions are not allowed. i. e. an inline function that calls itself is not
allowed.
- You can specify inline in the interface of a unit or in the implementation, the result
is the same.
- If you declare an inline function in the interface part of the unit, then the
implementation must appear before the first use of this function, or the compiler will
not inline it.