How can I create an alias for a function?
For example:
procedure DoSomething(...params...); cdecl; external 'useful';
const
DoAliasSomething = DoSomething;fpc does not allow this. So how can it be done?
Mattias

Mailing lists / fpc-pascal / 2007-10
9 messages · 5 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
How can I create an alias for a function?
For example:
procedure DoSomething(...params...); cdecl; external 'useful';
const
DoAliasSomething = DoSomething;fpc does not allow this. So how can it be done?
Mattias
program test;
procedure something; external name 'something';
Type
TProcedure = Procedure;
const
DoSomething : TProcedure = @something;
begin
end.Works fine.
Michael.
Yes, but I hoped to declare it in situ - without adding another type. ;) The reason is that I'm auto translating some C headers that contains aliases for functions.
Mattias
Op Thu, 4 Oct 2007, schreef Mattias Gaertner:
Yes, but I hoped to declare it in situ - without adding another type. ;) The reason is that I'm auto translating some C headers that contains aliases for functions.
procedure DoAliasSomething(...params...); cdecl; external 'useful';... is another approach.
Daniël
Ok. I implemented that.
I'm curious: Why does fpc not allow
const FuncAlias = MyFunc;
?
Mattias
Op Sat, 6 Oct 2007, schreef Mattias Gaertner:
It is not part of the Pascal language, not implemented by any other compiler and nobody ever saw a need to implement such an extension.
Daniël
On Thu, 4 Oct 2007 20:17:36 +0200 (CEST) Ok. I implemented that. I'm curious: Why does…
Yuck, that reminds me of C++ templates. it allows you to alias "{" as "begin" (for example) and also to make such aliases... it can create a lot of problems when people does not fully understand what you have done.
I can think on other way to implement "alias":
procedure OriginalProc(..).. {$IFDEF USEINLINE_ALIAS}inline;{$ENDIF}
begin
end;
...
procedure AliasProc(...);
begin
{$DEFINE USEINLINE_ALIAS}
OriginalProc(...);
{$UNDEF USEINLINE_ALIAS}
end;But it looks so ugly ...
Mattias
Ido
Sounds more like macros, than templates.
And it's even more complicate. ;)
Mattias
Yuck, that reminds me of C++ templates. it allows you to alias "{" as "begin" (for…
Hi!
Are you sure this works? AFAIK the "preprocessor" doesn't follow function calls but simply reads the .pas file from its first line to the end.
Another problem is that the OP wanted to alias external functions, where he can't define them as inline.
But he can reverse your approach:
Procedure NewName(...); inline;
Begin
OriginalProc(...);
End;Bye
Hansi