On Monday, July 10, 2017 at 6:59:48 PM UTC-7,
robin....@gmail.com wrote:
(snip, previous discussion said)
> > > The key here is that for the bounds of the target to be
> > > transmitted to the pointer, the reference must be a WHOLE ARRAY.
> > > Otherwise LBOUND must be 1.
(then I said)
> > For comparison purposes only, note that the PL/I array convention
> > always uses the declared array bounds.
> That's because the array bounds are passed in a descriptor,
> which contains the upper and lower bounds, as well as the address
> of the array.
Fortran assumed shape are passed by descriptor, too, but
with different information. The descriptor might just pass
the extent if each subscript. In the called routine,
the array will have lower bound of 1, and appropriate
upper bound.
> > There is nothing like assumed size in PL/I.
> What? Dummy arguments in Fortran are defined with * for each bound.
> That is how the corresponding facility in PL/I is used.
Assumed size, along with explicit shape, does not pass bounds
information, (or if it does, it is ignored). The dummy array
can have different rank, and/or different extent of each
dimension, as long as it stays within the number of element
of the actual array. Even more, one can pass an array element,
and the called routine can use any array element from that one,
to the end of the array. There is no such feature in PL/I.
(It would be interesting to see what the Fortran to PL/I
converter did with this one.)
> > This might be inconvenient. You can't add, or even
> > assign, arrays with different LBOUND, without a loop.
> But most programmers choose a consistent lower bound, such as 0 or 1.
In that case, there is no problem. Sometimes, one wants to
use a routine written by someone else. But even consider:
dcl (a(-2:3), b(0:5), c(2:7)) float bin(23);
you can't:
a=b+c;
or even:
a=c;
because the bounds don't match. On the other hand:
real a(-2:3), b(0:5), c(2:7)
(and assuming that they have appropriate values)
a=b+c
the six elements of b will be added to the six element
of c, and the sum assigned to a.
> > Subroutines
> > always need to use LBOUND and UBOUND to loop over the whole array,
> > except in cases where array expressions work.
> That's the same in Fortran.
No. In most cases, the case in this thread being a
counterexample, the called routine can:
do i=1, size(a,1)
a(i)=a(i)+1
enddo
> > Not so convenient, but nice and consistent. You only need to
> > learn one rule, and always apply that rule.
> Indeed.
Even more interesting, the descriptor defined for VAX in
the 1970's is appropriate for calling between Fortran and PL/I.
For the PL/I calling convention, you don't need the address
of the first element of the array, you need the address of
the virtual origin, the element with all subscripts zero
(which may or may not be inside the array). For the Fortran
assumed shape case, you can find all the array elements with
the address of the first element, and the extents of each.
The VAX descriptor passes the actual origin, virtual origin,
upper and lower bounds, and extent for each dimension.
Fortran programs can call PL/I, or PL/I programs call Fortran.
(snip of unrelated features)