[fpc-pascal] Procedural parameters
Hairy Pixels
genericptr at gmail.com
Sun Dec 15 12:28:25 CET 2024
On Dec 15, 2024 at 5:15:33 PM, Jonas Maebe via fpc-pascal <
fpc-pascal at lists.freepascal.org> wrote:
> It's because unlike in Borland Pascal, procvars in ISO Pascal captured
> the stack frame and allowed you to access local variables of the caller.
> By only allowing the declaration in the procedure header, this ensured
> the captured context could never escape the scope in which it was valid:
> after the scope in which it was valid was exited, the declaration would
> not longer exist either.
>
> FPC does allow you to capture these outside the scope where they are
> valid (using "is nested" procvar declarations), but the result is also
> that you can call them once they are no longer valid.
>
Ok that makes sense now. That’s interesting they crossed paths and never
joined the two designs in any of the compilers.
My opinion currently is that anonymous procedure types in parameters are
ugly/less readable but are better than the alternative of declaring types
that are only ever intended for a single procedure anyways. I find it makes
lots of types like “TMyProcedureCallback”which are single use and just
introduce extra names so I side with the ISO standard over Borland here.
Also noteworthy is ISO standard can accommodate generics which Borland’s
design can not. Did ISO standard allow pointer types in parameters too? It
seems like an arbitrary choice to allow pointer types on fields but not
parameters (same for procedures). Maybe another Borland idea?
Regards,
Ryan Joseph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20241215/a9fcc0f8/attachment.htm>
More information about the fpc-pascal
mailing list