[fpc-devel] Function variables and overload

Bram Kuijvenhoven kuifwaremailinglists at xs4all.nl
Fri Jul 1 22:45:13 CEST 2005


Peter Vreman wrote:
>>Would it be possible to get something like
>>
>>  L.Sort(@ICmp(PBigInt,PBigInt));
>>
>>in case ICmp is overloaded? If we could add the parameter
>>types, there would be no more ambiguity, the compiler would
> 
> There is ambiguity with a normal call to the function. The compiler sees
> the ( and thinks it is parsing a call to Icmp().

So, perhaps it would be nice if there was a way to declare an alias for overloaded functions? E.g.


type
  TNoParamFunc = function:boolean;
  TIntParamFunc = function(i:integer):boolean;

function MyOverloadedFunc:boolean; alias MyOverLoadedFuncNoParams;
function MyOverloadedFunc(i:integer):boolean; alias MyOverLoadedFuncInt;

procedure MyProc(f:TNoParamFunc);
procedure MyProc(f:TIntParamFunc); // so MyProc is also overloaded

...

MyProc(@MyOverLoadedFuncNoParams);
MyProc(@MyOverLoadedFuncInt);


This example also demonstrates exactly why we can't use the list of possible parameter types of MyProc in order to determine which overloaded function to pass.

One might argue this 'alias' construction takes away the purpose of overloading functions (which, simply put, is convenience for the programmer I think), but that is not neccessarily true because you only need to use the 'long' alias in relatively rare cases such as MyProc(@MyOverloadedFunc).

Another note is that the 'alias' keyword might already be in use for some other purpose (I don't exactly remember which), so we might need another keyword or construction to give alias names.


Regards,

Bram




More information about the fpc-devel mailing list