[fpc-devel] Local procedures as procedural parameter

olle.r at automagika.se olle.r at automagika.se
Mon Mar 14 10:37:16 CET 2005


> On Mon, 14 Mar 2005, Adriaan van Os wrote:
>
>> 7. Consider the following program:
>>
>> 	program func;
>>
>> 	type tfun = function( x: real): real;
>>
>> 	procedure iso_fun( function f( x: real): real);
>> 	begin
>> 	end;
>>
>> 	procedure typ_fun( pf: tfun);
>> 	begin
>> 	end;
>>
>> 	procedure somefun;
>>
>> 		function f( x: real): real;
>> 		begin
>> 		 	f:= x
>> 		end;
>>
>> 	begin
>> 		iso_fun( f);
>> 		typ_fun( f); {procedural variable can't get nested routiine}
>> 	end;
>>
>> 	begin
>> 	end.
>
> 1. What happens if f would use a variable from somefun, and f is called
>     when somefun is no longer executed ?

Yes this is a problem, but it can be solved by not allowing an iso style
procedure parameter to be stored in a variable. It should only be allowed
to be passed to another procedure or to be called.

In fact standard pascal does not allow procedure variables, only procedure
parameters (note the difference). I suppose the above problem is the
reason.

> 2. I see no difference whatsoever between typ_fun and iso_fun, except
>     the use of an extra type, which, in my opinion, does not change
>     anything to the usage or code of these functions. If one is allowed,
>     the other should be allowed as well.

No, and at present there is no difference in generated code.

On could add support for nestable procedure parameters, by adding a
directive 'nestable' or 'isoproc' or the like, to the procedure parameter.

But since traditionally the iso style is used in original pascal where you
expect nestability, and the typed style where you want to be able to store
the procedure in a var, one could add this meaning to the different
syntaxes. This is then also compatible with Metrowerks Pascal.

This do not excludes for adding a directive also, for those cases where
one want to combine the clearness of using procedure types with the
ability to nest. Or to other language modes of fpc.

Olle





More information about the fpc-devel mailing list