Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site lanl.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!cmcl2!lanl!jlg From: jlg@lanl.ARPA Newsgroups: net.lang Subject: Re: Constants in subroutine calls Message-ID: <19235@lanl.ARPA> Date: Thu, 10-Jan-85 14:24:57 EST Article-I.D.: lanl.19235 Posted: Thu Jan 10 14:24:57 1985 Date-Received: Mon, 14-Jan-85 13:41:34 EST References: <6599@brl-tgr.ARPA> <979@opus.UUCP> Sender: newsreader@lanl.ARPA Organization: Los Alamos National Laboratory Lines: 41 > 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. A lot of Fortran compilers do that. The CRAY compiler makes a copy of the constant and passes the address of the copy down to the subroutines. That way, if one of the subroutines changes the constant's value, only the copy is changed. The CRAY doesn't have 'read-only' memory locks, so it can't detect errors for this case (this may be the intended semanitcs anyway, see example below). SUBROUTINE A(R) !PRINT THE PRODUCT OF R AND (R+1), RETURN R+1 TEMP=R CALL SUCC(R) PRINT *,TEMP*R RETURN END SUBROUTINE SUCC(R) !RETURN SUCCESSOR OF R R=R+1 RETURN END Subroutine A will work correctly on the CRAY, even when its argument is a constant. The 'error' doesn't propagate back up to the calling routine, since only a copy of the constant was altered. (This is an admittedly contrived example, but it does demonstrate the point. I have used this technique to advantage before - it eliminates the need to use dummy variables to pass constant values to subroutines when I don't care about the returned value. I always carefully flag this trick as being non-standard.) The CRAY compiler is standard conforming too, since the standard doesn't require non-conforming code to be reported or corrected. The standard only requires that conforming programs be executed correctly. James Giles