[fpc-devel] nestedprocvar questions
Craig Peterson
craig at scootersoftware.com
Tue Jul 31 22:40:19 CEST 2012
Hi Sven,
On 7/31/2012 3:11 PM, Sven Barth wrote:
> Delphi does not use the "@" to designate the function address, so this
> isn't to take the address of a function/method. In Delphi you just use
> "r" (in your example).
Normally Delphi doesn't allow assigning local functions to procedure
variables or arguments (just like FPC without 'nestedprocvar'). If the
nested function doesn't access arguments or variables in the outer scope
it generates the stack frame differently and the resulting function is
identical to a standalone non-nested one. You can then use @ to bypass
the typechecking.
What David posted is working Delphi code. We use that style in a few
places to better group and encapsulate procedures for callbacks without
polluting the unit namespace.
> Adding "nestedprocvar" automatically wouldn't change anything as you'd
> still need "is nested" to have a procvar to which nested functions can
> be passed to.
The posted code crashes with an EAccessViolation if you run it using
FreePascal's default behavior. Adding {$modeswitch nestedprocvar} and
nothing else makes it work correctly, so there's some change in compiler
behavior even if "is nested" isn't used.
> How exactly do you mean this?
Is the behavior described above (the $modeswitch without "is nested")
intentional behavior we can rely on, or an unexpected side effect? Can
it be added to {$MODE DELPHI} to increase Delphi compatibility?
Regards,
Craig Peterson
Scooter Software
More information about the fpc-devel
mailing list