[fpc-pascal] How does inline work?
jonas.maebe at elis.ugent.be
Sun Nov 22 12:25:32 CET 2009
On 22 Nov 2009, at 10:10, Thierry Coq wrote:
> I'm trying to use inline to remove unnecessary debugging code, such as the following code, with FPC 2.3.1 on Windows, when compiling for production.
> However when I compile the code, at O1 optimisation level (my default), the call to DebugInfo is still present in the generated assembler.
Always provide a compilable sample with the full compiler invocation when reporting problems. After guessing how your the full source code looks and compiling it, the call is removed here:
$ cat tt.pp
TForm1 = class
procedure DebugInfo; inline;
$ fpc -O1 -al tt -Sd
Free Pascal Compiler version 2.4.0rc1 [2009/10/24] for i386
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Darwin for i386
28 lines compiled, 0.0 sec
$ cat tt.s
# Temps allocated between ebp-4 and ebp-4
#  begin
# Var $self located at ebp-4
#  end;
I guess the real case in which you observe that behaviour is more complicated, with circular dependencies between implementation units, or whereby the implementation of the "inline" routine appears only after it is called. In the former case you have to recompile several times before all inline statements can take effect, since the compiler can only methods for which it knows the implementation at the point when these methods are called. In the latter case, the compiler will not be able to inline the routine in the unit before its implementation is parsed.
More information about the fpc-pascal