<div dir="auto"><div class="gmail_quote" dir="auto"><div dir="ltr">Am Do., 15. Nov. 2018, 12:26 hat Marcos Douglas B. Santos <<a href="mailto:md@delfire.net">md@delfire.net</a>> geschrieben:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, Nov 15, 2018 at 8:15 AM Sven Barth via fpc-pascal<br>
<<a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-pascal@lists.freepascal.org</a>> wrote:<br>
><br>
> Am Do., 15. Nov. 2018, 10:17 hat Ryan Joseph <<a href="mailto:ryan@thealchemistguild.com" target="_blank" rel="noreferrer">ryan@thealchemistguild.com</a>> geschrieben:<br>
>><br>
>> Is passing nested procs outside of the calling scope relying on undefined behavior? It doesn’t seem like this should be allowed.<br>
><br>
><br>
> See the notes mentioned here: <a href="http://wiki.freepascal.org/FPC_New_Features_2.6.0#Support_for_nested_procedure_variables" rel="noreferrer noreferrer" target="_blank">http://wiki.freepascal.org/FPC_New_Features_2.6.0#Support_for_nested_procedure_variables</a><br>
><br>
> Don't know if it is documented as such, but if not, it should be.<br>
<br>
If I understood correctly, this can be used in all cases of anonymous<br>
functions, with the advantage to make the code more readable and<br>
"Pascalish".<br>
Am I right?<br></blockquote></div><div dir="auto"><br></div><div dir="auto">No, because function references (which is the name of the variables for anonymous functions) store the captured variables in an automatically created and managed object. Nested functions simply work on the stack. So passing them outside of the context of the function they're declared in will result in garbage. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div>