[fpc-pascal] Passing nested procs out?
Sven Barth
pascaldragon at googlemail.com
Thu Nov 15 14:19:42 CET 2018
Am Do., 15. Nov. 2018, 12:26 hat Marcos Douglas B. Santos <md at delfire.net>
geschrieben:
> On Thu, Nov 15, 2018 at 8:15 AM Sven Barth via fpc-pascal
> <fpc-pascal at lists.freepascal.org> wrote:
> >
> > Am Do., 15. Nov. 2018, 10:17 hat Ryan Joseph <ryan at thealchemistguild.com>
> geschrieben:
> >>
> >> Is passing nested procs outside of the calling scope relying on
> undefined behavior? It doesn’t seem like this should be allowed.
> >
> >
> > See the notes mentioned here:
> http://wiki.freepascal.org/FPC_New_Features_2.6.0#Support_for_nested_procedure_variables
> >
> > Don't know if it is documented as such, but if not, it should be.
>
> If I understood correctly, this can be used in all cases of anonymous
> functions, with the advantage to make the code more readable and
> "Pascalish".
> Am I right?
>
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.
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20181115/aa765beb/attachment.html>
More information about the fpc-pascal
mailing list