Re: Pointers to non-contiguous array slices
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
- Date: Sun, 2 Jan 2011 02:13:41 +0000 (UTC)
Richard Maine <nospam@xxxxxxxxxxxxx> wrote:
(snip on LOC(array section) not returning the address of the array)
Yep. That's exactly the source of the mistaken data I recall from
before. It is what you (well, I anyway) would expect from a LOC function
that was not specifically written with f90 array slices in mind and
integrated with the compiler.
Note in particular the "integrated with the compiler" part. It cannot be
done as an addon. Used to be that many things assumed Fortran data would
be passed by address. I've seen LOC functions for Fortran written in C.
In fact, that's pretty trivial to do if you assume that its argument
will be passed by address.
Well, there is also C_LOC for calling C routines that expect
a C pointer.
But I first knew LOC with VAX/VMS, along with the VAX defined
%VAL, %REF, and %DESCR to force a call by method for a specific
argument. First, many VMS system service routines expected pass
by value for some arguments. Also, you code store the LOC of something
in an integer variable and pass it using %VAL() to a routine expecting
a %REF argument.
But array slices are not passed by address. They can't be, as an address
is not sufficient information for a slice. You are usually going to see
one of two behaviors when array slices are passed.
VAX had %DESCR before Fortran had the need for descriptors.
Even more, the descriptor defined for it includes both the
address of the first element (needed for Fortran 90 assumed
shape) and the address of the virtual origin (element with
all subscripts zero) needed for PL/I. Assuming it is done
right, calls between Fortran assumed shape and PL/I should
work!
1. A descriptor is generated, and the address of that descriptor is
passed.
or
2. A contiguous copy is made and the address of that copy is passed.
For the descriptor thing to happen, the called procedure has to expect
such a descriptor and both the caller and callee have to agree about
this convention. That's likely to happen when you have an assumed-shape
(not assumed-size) dummy argument. It also requires an explicit
interface. Assumed-shape dummy arguments always require an explicit
interface and this is basically why - because the caller has to know
that a descriptor is expected; the explicit interface is how that
information is communicated.
-- glen
.
- References:
- Pointers to non-contiguous array slices
- From: James Tursa
- Re: Pointers to non-contiguous array slices
- From: Ron Shepard
- Re: Pointers to non-contiguous array slices
- From: steve
- Re: Pointers to non-contiguous array slices
- From: James Tursa
- Re: Pointers to non-contiguous array slices
- From: James Tursa
- Re: Pointers to non-contiguous array slices
- From: Richard Maine
- Pointers to non-contiguous array slices
- Prev by Date: Re: EXTERNAL keyword
- Next by Date: Re: EXTERNAL keyword
- Previous by thread: Re: Pointers to non-contiguous array slices
- Next by thread: Re: Pointers to non-contiguous array slices
- Index(es):
Relevant Pages
|