(snip, I wrote)
>> The OS/360 Fortran compilers (G and H) make local copies of scalar
>> variables, and then copy them back before return.  (Usually
>> described as call by value result.)  That is legal Fortran.

> FORTRAN tries pretty hard to accommodate the idiosyncrasies
> of various implementations.  I suppose that to make this all
> work the Standard must contain a statement that if a variable
> is passed as a parameter but the called routine modifies it
> via a COMMON block, the effect is implementation-dependent.

There are a number of cases, most of which come out as
anti-aliasing rules.  Partly it is to allow for optimization,
when the optimizer shouldn't have to figure out when something
might change.  That applies both to argument also in common,
and repeated use of the same argument.

>> For a Fortran call, local variables will have compile time
>> (relocatable) address constants, but dummy arguments arrays
>> will use the address passed in with the call.

>> PL/I passes the address of a temporary variable for expression
>> arguments, or arguments known to have different attributes.

>> To be most consistent with the OS/360 calling conventions,
>> as a series of A-type address constants, the last with the high
>> bit set, one would either pass addresses of copies, or expect
>> the called routine to make copies.  That would allow for calls
>> between C and other languages.

> But it doesn't.  If the actual parameter is a pointer, IBM's
> C places not the address of that parameter but its value on
> the stack (or in the parameter block).

Note that Fortran places the address in the parameter block,
either a compile time constant or run time passed argument.
The important point being that, at least with the traditional
convention, the parameter block values aren't modified.

It is non-standard to mix pointers and integers without a cast
on function call, though many old C programs did it.
So, you should be able to use a different calling method for
pointers and non-pointers.   It gets more complicated in
the varargs case, but I believe it still works.

Having the calling routine pass the address of a copy should
always work, though it a little less convenient and probably
slower in some cases.  Having the called routine make the copy
allows for no copy in the case where the (pass by) value
isn't changed.  Note that C allows structures, including
structs holding arrays, as arguments, but not, pass by value,
arrays.  (An array name, by itself, means the array address.)

Passing the address for pointers and arrays in the
parameter block allows for calls to/from Fortran where the dummy
argument or actual argument (Fortran terms) are arrays.

For scalars passed between C and Fortran, it is natural to instead
pass a pointer.  Fortran will do this by default, C with the &
operator.  Though Fortran now allows for call by value with the
VALUE attribute, most likely the common convention being to
pass the address.

-- glen

Reply via email to