[comp.lang.c] FORTRAN clarification

pmk@hall.cray.com (Peter Klausler) (12/24/87)

In article <1453@cuuxb.ATT.COM>, mmengel@cuuxb.ATT.COM (Marc W. Mengel) writes
(within an otherwise compelling argument in favor of 'noalias' in ANSI C):

> Fortran uses copy-in copy-out address passing, and (in current
> implementations) doesn't have an address-of operator. Therefore
> aliasing is much less of a problem.  ... [example deleted] ...
> Fortran, since it uses copy-in, copy-out argument passing,
> does not have this problem.

This is only partly right.  No FORTRAN implementation that I know of
(including IBM, UNIVAC/Sperry/UNISYS, CDC, and our three compilers)
passes arguments in this manner; pass-by-address is invariably used.

However, aliasing is specifically proscribed by the ANS for FORTRAN.
The following is illegal usage, although few systems will detect it.

*	"Real programmers" will note that this code will produce different
*	results depending on whether the 10 loop is vectorized.
*	Hint: What gets stored into C(65)?
	PROGRAM BAR
	DIMENSION C(96)
	CALL FOO (C(33), C(1))
	END
	SUBROUTINE FOO (A,B)
	DIMENSION A(64), B(64)
	DO 10 I=1,64
 10	A(I) = B(I)
	RETURN
	END

So Marc is right when he writes that FORTRAN has fewer problems with
aliasing than does C, but for the wrong reasons.

This aspect of FORTRAN allows an optimizing compiler all sorts of leeway
that an optimizing C compiler, without 'noalias', just can't have.
'noalias' should facilitate automatic vectorization and multiprocessing
of C, if I understand its meaning correctly.

Interestingly enough, Ada provides for pass-by-copying arguments, but
does not require implementations to actually copy data. I forget how
aliasing is addressed; perhaps some guru can mail me the story.