Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site harvard.ARPA
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!stew
From: stew@harvard.ARPA (Stew Rubenstein)
Newsgroups: net.lang
Subject: Re: Constants in subroutine calls
Message-ID: <275@harvard.ARPA>
Date: Thu, 10-Jan-85 02:20:31 EST
Article-I.D.: harvard.275
Posted: Thu Jan 10 02:20:31 1985
Date-Received: Mon, 14-Jan-85 13:29:34 EST
References: <6599@brl-tgr.ARPA> <979@opus.UUCP> <1146@ut-ngp.UUCP>
Organization: Aiken Computation Laboratory, Harvard
Lines: 34

Joe Orost writes:

>  Consider the following:
> 
> 	CALL A(1.0)
> 
> 	SUBROUTINE A(R)
> 	CALL B(R)
> 	END
> 
> 	SUBROUTINE B(R)
> 	...
> 	END
> 
> Since scalar arguments are passed by value, the value 1.0 is copied into "R"
> on entry to subroutine A.  On exit from A, the compiler can't know if B
> changed the value of R (it also doesn't know that the argument is a
> constant), so it must copy back the local copy of R into the constant 1.0.
> This prevents us from storing the constant in read-only memory.  It seems
> that the only way thay can get away with storing passed constants in
> read-only memory is to CHECK what was passed on subroutine exit, and skip the
> update code if a constant was passed (yick!).

In VMS Fortran, everything is passed by reference.  Thus, in subroutine A,
it doesn't copy 1.0 into "R", it copies the ADDRESS of the constant into
the argument list to be passed to subroutine "B".  No copying of the value
is necessary.  If subroutine "B" tries to alter the contents of this address,
it will generate an access violation.

Stew
-- 
-----------------------
Stew Rubenstein     UUCP: ihnp4!harvard!stew
Harvard Chemistry   ARPA: stew@harvard