[fpc-pascal] Passing nested procs out?
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>
> 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>
> >> 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:
> > 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
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal