P
paul.richard.thomas
(F>=90 also adds optional specification of INTENT IN/OUT/INOUT,
the first two of which *may* copy only one direction. F03 adds
optional explicit VALUE, and C 'interop' features that as one would
expect support the C method. Some compilers did (and do) have
extensions to specify by-ref/value and other calling conventions,
but always as extensions, and TTBOMLK always using either
(pseudo-)function syntax or comment(-like) syntax, not slashes.)
The VALUE attribute, introduced by fortran 2003, enables passibling by
value. Otherwise passing by reference is the norm.
The only thing I know of that is even reasonably close is that
PL/I normally passes by-reference, but specifies that extra
*parentheses* around an argument mean it is first copied to a
temporary (and not copied back) giving the effect of by-value.
Fortran does this too. For example:
$ cat dogs.f90
integer :: i = 42
call foo((i))
print *, i
call foo (i)
print *, i
call bar (i)
print *, i
contains
subroutine foo(i)
integer :: i
i = i + 1
end subroutine
subroutine bar(i)
integer, value :: i
i = i + 1
end subroutine
end
$ /irun/bin/gfortran -fdump-tree-original dogs.f90
$ ./a
42
43
43
$ cat dogs*nal
bar (integer(kind=4) i)
{
i = i + 1;
foo (integer(kind=4) & i)
{
*i = *i + 1;
MAIN__ ()
{
static integer(kind=4) i = 42;
static integer(kind=4) options.0[8] = {68, 255, 0, 0, 0, 1, 0, 1};
static void foo (integer(kind=4) &);
static void bar (integer(kind=4));
_gfortran_set_options (8, (void *) &options.0);
{
integer(kind=4) D.642;
D.642 = i;
foo (&D.642);
}
{
/* PRINT eliminated here */
}
foo (&i);
{
/* PRINT eliminated here */
}
bar (i);
{
/* PRINT eliminated here */
}
}
where the code for the PRINT statements has been cut for clarity.
Note the copy in for the first call to foo, using D.639 as temporary,
and the passing by reference of i in the second call. The passing by
value in BAR is evident both in the code for bar and its call.
Paul