smart compilers

jhf at lanl.ARPA jhf at lanl.ARPA
Thu Jan 10 08:57:00 AEST 1985


> > I thought Fortran-77 required constant actual parameters to be
> > "copied in" rather than passed by reference?
> 
> FORTRAN parameters are always pass-by-reference.
> -- 
> D Gary Grady
> Duke University Computation Center, Durham, NC  27706

Absolutely not.  Both reference and value-result are acceptable parameter
passing methods for Fortran.  Programs that are sensitive to the difference,
i.e., that create aliases to actual parameters ("dummy arguments") which
they redefine, are not standard conforming.  This restriction, in my opinion,
is entirely appropriate.  Efficiency of parameter passing is of the greatest
importance to the overall quality of a compiler's target code, and archi-
tectural features and other circumstances may make one of these methods
much more desirable than the other.  The compiler writer should be free to
choose the appropriate technique, and not be restricted to one of them
for the sake of guaranteeing the effects of some bad programs.

I might note that Ada imposes a similar restriction on parameters, but,
incredibly, the Pascal standard does not.  It requires call-by-reference
for var parameters!  (At least, it did the last time I looked.  If the
situation has changed, I stand duly corrected and chastised.)  I think
this is a huge mistake.  Not only does it unreasonably restrict
implementations, but it makes impossible the removal of a wart in the
language, that components of packed arrays or records may not be passed
as var parameters.  This restriction is there, of course, because there
will generally not be a reasonable way to implement call-by-reference for
objects that are not aligned on an addressable bit boundary.  This
directly conflicts with the notion that packed types differ from their
unpacked counterparts only in their storage requirements and access times.
What the Pascal standard should have done is to restrict the aliasing
of var parameters in a manner similar to Fortran or Ada, and then to
remove the restriction on passing components of packed structures.
(Most compilers would implement this by copy-in-copy-out on the calling
side, where necessary.)

Joe Fasel
Los Alamos National Laboratory
jhf at lanl.{arpa,uucp}



More information about the Comp.unix.wizards mailing list