<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Hairy Pixels <<a href="mailto:genericptr@gmail.com">genericptr@gmail.com</a>> schrieb am Fr., 3. Nov. 2023, 12:37:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Nov 3, 2023, at 2:08 PM, Sven Barth <<a href="mailto:pascaldragon@googlemail.com" target="_blank" rel="noreferrer">pascaldragon@googlemail.com</a>> wrote:<br>
> <br>
> 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. <br>
> <br>
<br>
Ok I misinterpreted what you previously said then.<br>
<br>
I think Swift does this because they only have a single function pointer type which serves all purposes while FPC has 4 distinct types.<br>
<br>
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.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">If you need a catch all type, then you should use function references. There is no need to invent yet another type.</div><div dir="auto">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.</div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>