[J3] Polymorphic dummy arrays

Malcolm Cohen malcolm at nag-j.co.jp
Mon Jan 7 20:28:10 EST 2019


Hi Jon,

 

There is no such restriction.

 

The compiler you mention that applies the restriction does so on the grounds that

1.	only an idiot would write code like that (IMNSHO!),
2.	it’s too complicated and messy to implement, therefore we can reject it under the “size and complexity” rule.

 

I suppose the compiler you mention should get around to lifting that restriction sometime, but frankly I’d rather work on things that are of actual use.  The user has no need to use an explicit-shape array here, it just makes life more complicated for everyone.

 

Cheers,

-- 

..............Malcolm Cohen, NAG Oxford/Tokyo.

 

From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Steidel, Jon L via J3
Sent: Tuesday, January 8, 2019 7:07 AM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Steidel, Jon L <jon.l.steidel at intel.com>
Subject: [J3] Polymorphic dummy arrays

 

Happy New Year,

 

I have a user that wants to be pointed to words in the standard that I cannot find.  I would appreciate any help anyone can offer.

 

Subroutine func has  a dummy argument  that is an array of polymorphic class T.  It is called with an actual argument array of type S, which extends type T.  The user wants to have the dummy array be explicit shape.  But passing a simple address to func is insufficient as the dummy argument is polymorphic; the subroutine needs to at least know the size of each element as well as a base address.  

 

program class_type_conv

 

implicit none

 

type :: t

integer :: i = 1

end type

 

type, extends(t) :: s

real :: r = 1.0

end type

 

type(s), dimension(1:2) :: x

 

call func(x)

print *,x(1)%i, x(1)%r

print *,x(2)%i, x(2)%r

 

contains

 

subroutine func(x)

!  class(t), dimension(1:2), intent(out) :: x   ! original test

class(t), dimension(:), intent(out) :: x           ! modified test

 

call inc(x)

end subroutine

 

subroutine inc(x)

type(t), dimension(1:2), intent(out) :: x

x(:)%i = x(:)%i + 1

end subroutine

 

end

 

One compiler I have access to diagnoses the declaration of the explicit shape dummy array in func (the commented out line) stating a polymorphic dummy array must be allocatable, pointer, or assumed shape. Passing a descriptor here solves the problem as there is element size or inter-element spacing information in the descriptor.  

 

I can a restriction that says a polymorphic object must have the POINTER or ALLOCATABLE attribute or be a dummy argument (C708).  I can also find a requirement that a procedure with a polymorphic dummy argument requires an explicit interface (15.4.2.2.)  But I cannot find a requirement that a dummy array of polymorphic objects must be assumed shape.  Can someone point me to those words?

 

Note that if the dummy polymorphic array is required to be assume shape, then passing this dummy array from as an actual argument func to the dummy argument x of inc is not legal.  15.5.2.4 Ordinary dummy variables, p2 sentence 3 states “If the actual argument is a polymorphic assumed-size array, the dummy argument shall be polymorphic.”  In subroutine inc, x is not polymorphic. 

 

 

Thanks,

 

-jon 

 

 

 

 

Disclaimer

The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. Please see our Privacy Notice <https://www.nag.co.uk/content/privacy-notice>  for information on how we process personal data and for details of how to stop or limit communications from us.

This e-mail has been scanned for all viruses and malware, and may have been automatically archived by Mimecast Ltd, an innovator in Software as a Service (SaaS) for business.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20190108/1082a15e/attachment.html>


More information about the J3 mailing list