[fpc-devel] Local procedures as procedural parameter
Marco van de Voort
marcov at stack.nl
Mon Mar 14 10:34:21 CET 2005
> On Mon, 14 Mar 2005, Jonas Maebe wrote:
> > to a regular procedural variable). You can only pass it as parameter to
> > procedures declared with an ISO-style procedure/function parameter, and since
> > its scope is limited to somefun, somefun will always be active when you can
> > do so.
>
> But the compiler can never guarantee this ?
>
> It seems to me that the following is perfectly valid code :
>
> Var
> StoredF : Function (x : real) : real
This is not allowed. Only TP style is allowed with VAR, so
var stored : TSomeFunc;
> When compiling this, there is no way the compiler can determine whether
> f (or storedf) will be a local procedure or a global one. To solve this,
> it would mean that each procedure variable would have to consist of 2
> things; A pointer and a type indicator.
No, they are simply two procvar types, and variables (properties/fields etc)
of the new type are not allowed, only params.
> >> 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.
> >
> > Well, it currently isn't in either our compiler or in Delphi. You cannot
> > declare a function type inside a parameter list for now. Maybe this was even
> > done on purpose to avoid clashes with ISO-style procedure parameters.
>
> Yes, but why would one be allowed and the other not ?
TP/BP was all about speed and footprint. The kind of solutions we
use now with compiler modi and several kinds of procvars was simply to
expensive at the time I think.
More information about the fpc-devel
mailing list