[fpc-pascal] Inline methods

Sven Barth pascaldragon at googlemail.com
Wed May 18 11:08:42 CEST 2016


Am 18.05.2016 11:07 schrieb "Sven Barth" <pascaldragon at googlemail.com>:
>
> Am 18.05.2016 10:06 schrieb "LacaK" <lacak at zoznam.sk>:
> >
> > Hi *,
> > is it possible inline also methods of objects (not regular procedures) ?
> > I have very simple class method, which call I need inline.
> > (looking at assembler code it is not inlined; I have looked also in
documentation, but I do not found article about inline and methods)
> >
> > Example:
> >
> > function T2DArray.Data(x, y: integer): PElement; inline;
> > begin
> >   Result := @FArray[x+y*Fx];
> > end;
>
> Yes. Inline needs to be declared at the declaration however and not the
implementation and any function or method that uses it (in the same unit)
needs to come afterwards if you want it to be inlined (for other units that
doesn't matter as long as you don't have circular dependencies, cause then
things get messy). On addition to that "inline" is only a hint for the
compiler, so there might be cases when the compiler decides not to inline.

Oh and it obviously won't work with virtual methods.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160518/42a579d0/attachment.html>


More information about the fpc-pascal mailing list