[J3] Polymorphic dummy arrays

Steidel, Jon L jon.l.steidel at intel.com
Tue Jan 8 11:14:29 EST 2019


Thanks all for your comments and letting me know what your favorite compilers do.  

Bob and Vipul you are correct; I should not have mentioned assumed-size in this discussion at all as it is a red herring here.  Sometimes I see "assumed-size" and read "assumed-shape".  Neurological disorder perhaps.

I believe there are two ways passing a type (S) actual array to a class (T) explicit shape array can be made to work.  Passing a copy is insufficient in this case because the called procedure func needs to know the size of an element of the actual argument (all it knows is the argument is class (T)). 
One solution would be to pass a hidden length argument, as many compilers do for character variables.  The other solution would be to force this case to pass by descriptor, which could be done since an explicit interface is required.  Both seem ugly.

-jon

-----Original Message-----
From: J3 [mailto:j3-bounces at mailman.j3-fortran.org] On Behalf Of Robert Corbett via J3
Sent: Monday, January 7, 2019 8:37 PM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Robert Corbett <rpcorbett at att.net>
Subject: Re: [J3] Polymorphic dummy arrays

The original question was whether a polymorphic array dummy argument had to be an assumed-shape array.  If assumed-size polymorphic array dummy arguments are permitted, the answer to that question is no.

As you say, explicit-shape dummy arguments passed as actual arguments can require copies.  Unlike the case of an assumed-size array, the shape of an explicit-shape array is known by the calling routine, which allows the copy to be done.  In the case of an assumed-size array, most implementations do not know the size of the array, and so they cannot know how many elements to copy.

Bob Corbett

> On Jan 7, 2019, at 3:18 PM, Bill Long via J3 <j3 at mailman.j3-fortran.org> wrote:
> 
> The original example did not have any assumed-size arrays.  However, in the case of the dummy being explicit-shape  (dimension(1:2)) it is still possible that copy-in/copy-out is required, since the elements of the dummy array correspond to elements of the actual that are (most likely) not contiguous in memory. 
> 
> Cheers,
> Bill
> 
>> On Jan 7, 2019, at 5:14 PM, Robert Corbett via J3 <j3 at mailman.j3-fortran.org> wrote:
>> 
>> I am not aware of such a restriction.  I recall that Oracle Fortran allows assumed-size polymorphic dummy arguments.  At the time, they were tricky to implement.  The ability to pass a polymorphic actual argument to a dummy argument that is not polymorphic requires making a copy.  That meant Oracle's implementation had to pass the size of assumed-size polymorphic arrays.  Later, the standard was modified via corrigenda to eliminate the need to make copies.
>> 
>> Robert Corbett



More information about the J3 mailing list