[comp.lang.fortran] FORTRAN parameter passing

peb@cs.purdue.EDU (Paul E. Buis) (08/07/89)

Most FORTRAN implementations seem to use call by reference for passing
parameters.  However, I have heard of some that use copy in, copy out.
Since aliasing in FORTRAN is illegal (even if compilers never try to
check for it), what portability problems may arise for the user if the
compiler uses this technique rather than the traditional one?

ags@mentor.cc.purdue.edu (Dave Seaman) (08/07/89)

In article <7584@medusa.cs.purdue.edu> peb@cs.purdue.EDU (Paul E. Buis) writes:
>Since aliasing in FORTRAN is illegal (even if compilers never try to
>check for it), what portability problems may arise for the user if the
>compiler uses this technique rather than the traditional one?

None, provided the programs are standard-conforming.

A common instance of nonconforming Fortran that is particularly insidious is
the failure to properly declare dummy arguments.  For example:

	real a(100)
	...
	call sub1(a,100)
	...
	end
	subroutine sub1(x,n)
	call clear(x,n)
	...
	end
	subroutine clear(y,n)
	real y(n)
	do 10 i=1,n
	  y(i) = 0.0
    10  continue
	end

Subroutine SUB1 has a dummy array X that is not declared.  The routine does not
use X in any way except to pass it along as an argument to subroutine CLEAR.
Most Fortrans let you get away with this, but not those that use
copy-in-copy-out for simple variables.  As far as the compiler can tell, X is a
simple variable in subroutine SUB1.

A variation on this problem has to do with passing external subroutines through
multiple levels of subroutines and forgetting that they must be declared
EXTERNAL at every intermediate level (not just the first level).

	"But it works on a VAX!"

-- 
Dave Seaman	  					
ags@seaman.cc.purdue.edu