Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA
Path: utzoo!watmath!clyde!burl!ulysses!allegra!bellcore!decvax!wanginst!ucadmus!harvard!seismo!brl-tgr!tgr!FIRTH@TL-20B.ARPA
From: FIRTH@TL-20B.ARPA
Newsgroups: net.unix-wizards
Subject: CALL NASTY(0.0) in Fortran
Message-ID: <7065@brl-tgr.ARPA>
Date: Mon, 7-Jan-85 11:39:40 EST
Article-I.D.: brl-tgr.7065
Posted: Mon Jan  7 11:39:40 1985
Date-Received: Wed, 9-Jan-85 02:19:05 EST
Sender: news@brl-tgr.ARPA
Organization: Ballistic Research Lab
Lines: 32

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
-------