Hargraves Gary wrote:
> May I please have a little clarification by my favourite rocket scientist on:
> that fortran is 'not pass by reference'.
>
> The default in fortran is (surely?!) that the argument suffers 'pass by
> reference' behaviour, whereas the default in vanilla C is that the argument
> suffers 'pass by copy' behaviour (to coin a phrase). That is in fortran
> (without any other specification) a change to the argument (alias) in the
> subroutine will result in a change to the pass (original) in the main.
>
> I postulate perhaps that Richard means: one cannot assume that the means to
> the end is actually pass by reference. Perhaps he will be kind enough to put
> me out of my misery at reading these potentially misleading comments.
>
> Specifically, I would like to confirm that the default standard in fortran is
> an effective 'pass by reference'.
Yes, by default any changes to the dummy argument remain as
the value of the actual argument after the procedure terminates.
No, that is not necessarily done using call-by-reference.
The difference is when the procedure is still in execution. Suppose
you make a change to the dummy argument, and then (somehow)
reference the actual argument before the procedure returns. In that
case, the actual argument may or may not reflect the new value
assigned to the dummy. In fact, it sometimes won't in most Fortran
implementations. This is because, regardless of how the argument
is passed, the optimizer often makes intermediate copies of the arguments.
Of course, it's illegal to reference the actual argument associated with
a changing dummy by any means except through that dummy argument
(with some specific exceptions pertaining to POINTERs). So, the
old rule of thumb is "if you can tell whether the implementation uses
call-by-reference or copy-in/copy-out, you've violated the standard."
--
J. Giles
|