CALL NASTY(0.0) in Fortran

FIRTH at TL-20B.ARPA FIRTH at TL-20B.ARPA
Tue Jan 8 02:39:40 AEST 1985


This note addresses the issue of fortran

	CALL NASTY(0.0)

where the body of NASTY promptly assigns 1.0 to 0.0!

I don't know which Fortran the programmer thought he was
writing, but certainly in Fortran 77 the compiler was right
and the user was wrong:

	"Actual arguments may be constants, function
	 references, expressions involving operators,
	 and expressions enclosed in parentheses if
	 and only if the associated dummy argument is 
	 a variable that is not defined during execution
	 of the referenced procedure"

	[ANSI-X3.9-1978, Para 15.9.2]

In other words, a program that passes a constant as actual
to a subroutine that assigs to the corresponding formal is
not legal Fortran, and the compiler is entitled (if it feels
sufficiently unfriendly) to mangle the non-program appropriately.

In passing: most programming languages contain restrictions
that are specifically intended to make optimisations safe, by
declaring illegal the "pathological" cases in which they are
unsafe.  Another example is the "no aliasing" rules of Fortran
[op cit, 15.9.3.6] and Ada [Mil-Std-1815 A, Ch 6.2 para 13]

Robert Firth
-------



More information about the Comp.unix.wizards mailing list