[fpc-pascal] alias a function + overload 'in'

Tomas Hajny XHajT03 at hajny.biz
Sun Dec 18 12:37:32 CET 2011


On 17 Dec 11, at 21:07, David Emerson wrote:

> two little questions
> 
> 1. Is it possible to make an alias to a function ... so rather than just 
> re-calling with the same parameters, it's actually the same thing? like the way 
> we can do, e.g., type natural = cardinal, or const GG = 6, but with a function?
 .
 .

There are multiple solutions possible:

1) Making the functions public and creating the aliases as external:

procedure X; public name 'X';
begin
 WriteLn (1);
end;

procedure Y; external name 'X';

begin
 X;
 Y;
end.


2) Using procedural variables / constants:

type
 TProc = procedure;

procedure X;
begin
 WriteLn (1);
end;

const
 Y: TProc = @X;
 
begin
 X;
 Y;
end.


3) Using inlining:

procedure X;
begin
 WriteLn (1);
end;

procedure Y; inline;
begin
 X;
end;
 
begin
 X;
 Y;
end.

Tomas




More information about the fpc-pascal mailing list