Protected parameters_(re)

Sat, 8 Mar 1997 01:57:43 +0100 (MET)


According to Frank Heckenbach:
> Does that mean that protected (not protected var) parameters are passed
> by value?  Especially in the case of large structures, can this be
> inefficient, taking up stack space and consuming time to copy the
> arguments?

Yes.  :-(

> Since protected parameters are read-only anyway, actually I see no need
> to distinguish between passing them by value or by reference. Of course,
> it would be best if the compiler could automatically choose the more
> efficient way of passing (i.e. small structures by value, and large ones
> by reference), no matter if declared as "protected", "protected var" or
> "const".

I agree.  But ...

> Or does the standard prescribe something different?

Yes.  It requires that the value of the protected formal parameter
cannot change during the execution of the function, so things like
the following require it to pass everything by value:

    Var
      X: Something;

    Procedure foo ( protected a: Something; Var b: Something );

    begin (* foo *)
      b:= SomeValue;
    end (* foo *);

    begin
      foo ( X, X );
    end.

(One might ask what purpose `protected' serves when it requires to
pass everything by value anyway ... ;-)

> Also, defining "Const" as "protected Var" is not completely compatible to BP,
> since in BP you can pass a calculated expression, not only an "lvalue" as a
> const parameter.

I have planned to enable this, too.  Then `Const' parameters will indeed
be something different than `protected' ones.  It could be a good idea
to pass small things by value for `Const' parameters ... and relatively
easy to implement ...

Okay, I am working on it, but ...

> But of course, these are no urgent issues, as long as one form of
> protected/const parameters works at all... :-)

... with low priority. ;-)

    Peter

  Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer
peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201]
       maintainer GNU Pascal - http://home.pages.de/~gnu-pascal/ [970125]


Peter Gerwinski (peter@agnes.dida.physik.uni-essen.de)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es