Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-04

nested procedure as parameter question

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bruce Bauman

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
CONFIDENTIALITY NOTICE: This e-mail is confidential and intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient, be advised that you have received this email in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please delete it from your computer and contact the sender.

Reply by email

Flávio Etrusco
to Bruce Bauman
Bruce Bauman wrote 29 lines
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

Reply by email

Bruce Bauman
to Flávio Etrusco

I did try it, and I got the same error message from the compiler. However, I can't be sure if the compiler didn't allow inlining for some other reason.

BTW, it would be nice if there were some equivalent to gcc's pragma inline_only(?) which says that the procedure MUST be inlined (or an error is generated).

-- Bruce

Earlier message 43 lines
-----Original Message----- From: On Behalf Of Flávio Etrusco Sent: Thursday, April 15, 2010 1:57 PM To: FPC-Pascal users discussions Subject: Re: [fpc-pascal] nested procedure as parameter question On Thu, Apr 15, 2010 at 2:51 PM, Bruce Bauman 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

Reply by email

Adriaan van Os
to Bruce Bauman: I am porting a large amount of existing Pascal code (MetaWare) to Free Pascal.…
Bruce Bauman wrote 7 lines
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:

See <http://bugs.freepascal.org/view.php?id=15925>

Regards,

Adriaan van Os

Reply by email