[fpc-devel] nestedprocvar questions

David Jenkins david at scootersoftware.com
Tue Jul 31 19:04:28 CEST 2012


Some questions about 'nestedprocvars' mode switch

We have a simplified version of the nested procedure calling 
demonstrated in tests/test/tmaclocalprocparam3d.pp.  It looks more or 
less like:

{$mode DELPHI}
{$modeswitch nestedprocvars}

type
   tnestedprocvar = function(AArg: string): boolean;


   procedure p1(AArg: string; pp: tnestedprocvar);
   begin
     if pp(AArg) then
       writeln('true');
   end;

   procedure q;

     function r(AArg: string): boolean;
     begin
       writeln(AArg)
       Result := true;
     end;

   begin
      p1('test string', @r);
   end;

Notice that it is $MODE DELPHI, that the proc var is a function, and that we do not access any external variables in the nested function.

Question #1:
There seems to be an interaction between $MODE DELPHI and the 'is nested' construct.  I.e. I cannot put the 'is nested' after the tnestedprocvar type and do the function passing with '@r'.  If I do the compiler complains about getting a pointer (@r) when it was expecting a function (..): boolean is nested.  So either I remove the'@' and just pass 'r' or I do not include the 'is nested'.

Is this correct?

Question #2:
This code is being compiled both with Delphi compiler and with FPC.  Delphi handles the nesting with no problem and with no 'is nested' directive.

Should nestedprocvar be included automatically with $MODE DELPHI for compatibility?

Question #3:
If we set up our code as above can we expect the compiler to be consistent in parameter set up for the next while?

Question #4:
If we set up our code as above (with no 'is nested') would it be safe to include access of an external variable (internal to procedure q) to the nested function?





More information about the fpc-devel mailing list