When a parameter is passed by reference, the system passes the formal parameter a reference to the place where the actual parameter is stored in memory. Passing a parameter by reference is essentially the same as passing it by name, except that the compiler does not create a thunk for a call-by-reference parameter. Any expressions passed by reference are, therefore, evaluated immediately and changed into simple values or pointers to simple values.
The effects of passing a parameter by reference are somewhat different in FORTRAN77 than in other languages. In non-FORTRAN languages, the effects of passing by reference are as follows:
-
When a simple variable is passed by reference, the effect is the same as if it had been passed by name. Changes made to the value of the formal parameter immediately affect the value of the actual parameter and vice versa.
-
In most languages, constants and complex expressions cannot be passed by reference; a syntax error results from an attempt to do so. However, simple expressions can be passed by reference. For a simple expression, the system passes a reference to the location of the element. This location never changes, even if the value of the subscript later changes. For example, suppose the actual parameter A[I] is passed to the formal parameter F and I has a value of 5. Formal parameter F becomes a reference to array element A[5]. Even if I is later assigned a different value, F remains a reference to A[5]. When F is read, it reflects the most recent value of A[5]. When F is assigned, it changes the value of A[5].
In FORTRAN77 the effects of passing by reference are as follows:
-
For simple variables of type integer, real, double precision, complex, or logical, two different kinds of call-by-reference passing are available. The default method is known as call-by-value-result. With this method, the value of the actual parameter is assigned to the formal parameter. Thereafter, assignments to the actual parameter have no effect on the formal parameter. Assignments to the formal parameter have no immediate effect on the actual parameter; however, when the procedure is exited, the value of the formal parameter is assigned to the actual parameter. The alternate method is true call-by-reference passing, in which the formal parameter receives a reference to the actual parameter itself; changes to the actual parameter are immediately visible to the formal parameter and vice versa. The programmer can request true call-by-reference passing by enclosing the formal parameter in slashes (/).
-
For parameters that are character variables, arrays, or subprograms, the parameter is always treated as a true call-by-reference parameter. Any changes to the actual parameter are immediately visible to the formal parameter and vice versa.
-
Constants of type integer, real, double precision, complex, or logical can be passed by reference, but character or array constants cannot. The receiving procedure can make assignments that change the value of the formal parameter, but the value of the actual parameter is never updated to reflect the change.
-
For an actual parameter that is a simple expression, the parameter is treated as either call-by-value-result, or true call-by-reference, depending on the way the formal parameter is declared. If the formal parameter is a character variable or array, then the parameter is treated as a true call-by-reference parameter. If the formal parameter is an integer, real, double precision, complex, or logical variable, then by default the parameter is treated as call-by-value-result; however, if the formal parameter is enclosed in slashes, the parameter is treated as true call-by-reference.
-
For an actual parameter that is a complex expression, the system evaluates the expression and passes the value to the formal parameter. The receiving procedure can make assignments that change the value of the formal parameter, but the value of the actual parameter remains unchanged.

