On 29/05/2022 07:21, Michael Van Canneyt via fpc-pascal wrote:


On Sun, 29 May 2022, Hairy Pixels via fpc-pascal wrote:

I’ve been testing out all the different function pointer types in FPC to
test their compatibility with each other and I noticed that “is nested”
can accept a global function declaration but “of object” can not.  What is
the reason for this exactly?  I wouldn’t expect nested function types to
accept global functions but since they do I wonder why “of object” is
different.

Because you're pushing a parameter which does not exist in the case of a
global function.

Actually afaik you push an extra param in for "is nested" as well as for "of object.

But for "of object" it is the first param, for "is nested" it is the last.

procedure TFoo.Bar(self: TBar; a: integer);
procedure NestedBar(a: integer; parentFp: pointer);

So in the code at the end of the mail, with a global function assigned to "p", it calls
  p(1, SomeValueForParentFp).
But the global "procedure f" just ignores the extra param.

If it was "of object", the "self" value would be first, and it would be in place of the parameter "a".


program Foo;
type TProc = procedure(a:integer) is nested;
var  p: TProc;

procedure f(a:integer);
begin
end;

begin
  p:= @f;
  p(1);
end.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to