Hairy Pixels <generic...@gmail.com> schrieb am Fr., 3. Nov. 2023, 12:37:

>
>
> > On Nov 3, 2023, at 2:08 PM, Sven Barth <pascaldra...@googlemail.com>
> wrote:
> >
> > By default the purpose of anonymous functions assigned to function
> references *is* that they can escape their scope. This will not change,
> because they were after all introduced for Delphi-compatibility and there
> won't be any designations that the value can't escape. If the compiler
> can't figure it out by its own (see above) then tough luck; use a feature
> better suited for that.
> >
>
> Ok I misinterpreted what you previously said then.
>
> I think Swift does this because they only have a single function pointer
> type which serves all purposes while FPC has 4 distinct types.
>
> IMO FPC needs this also since it's not possible for libraries to know
> which kind of function the caller may provide. Behind the scenes the
> different types are required (global, nested, method, reference) but there
> should be a way to unify these into single type. How to store the capturer
> and manage its memory would be an open question though.
>

If you need a catch all type, then you should use function references.
There is no need to invent yet another type.
The only thing it can not handle is the assignment of nested function
pointers (in contrast to nested functions directly), because they can only
ever be used in a function that is below the one where the nested function
was assigned which is not a guaranteed property for function references.

Regards,
Sven

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

Reply via email to