[fpc-pascal] nested procedure as parameter question

Flávio Etrusco flavio.etrusco at gmail.com
Thu Apr 15 19:56:48 CEST 2010


On Thu, Apr 15, 2010 at 2:51 PM, Bruce Bauman
<bruce.bauman at andesaservices.com> wrote:
> I am porting a large amount of existing Pascal code (MetaWare) to Free
> Pascal. Unfortunately, this code makes extensive use of nested
> procedures, and the nested procedures often reference variables in the
> enclosing scope.
>
> I know that I can't pass the nested routine by address to another
> procedure; I get errors like the following:
>
> intjob4_intday.pas(400,47) Error: Incompatible type for arg no. 3: Got
> "<address of local procedure(StdStr04);Register>", expected "<procedure
> variable type of procedure(StdStr04);Register>"
>
> Can I get around this restriction by inlining the procedure which is
> being passed the nested procedure as an argument?
>
> For example, let's say the A is the enclosing procedure, B is the nested
> procedure, and B is being passed as a parameter to C.
>
> Procedure A;
>    Procedure B;
>
> Begin
>    C(@B);
> End;
>
> Can I inline procedure C? Will this work? (My initial test with fpc
> 2.4.0 suggests it doesn't work).
>
> -- Bruce

I don't think this will work, but why didn't you try it? It would be
very nice if the nested procedures which don't access outside vars
were allowed to be used as non-local procedure...

Flávio



More information about the fpc-pascal mailing list