(j3.2006) assumed-size polymorphic actual arguments

Robert Corbett robert.corbett
Wed Jan 26 05:49:50 EST 2011


The following program appears to be standard conforming according
to the Fortran standard as written.

------------------------------------------------------------------

       MODULE TYPES
         PRIVATE
         PUBLIC REC, REC2

         TYPE REC
           INTEGER A
         END TYPE

         TYPE, EXTENDS(REC) :: REC2
           INTEGER B
         END TYPE
       END

       SUBROUTINE SUB1(A, N)
         USE TYPES
         CLASS(REC), INTENT(IN) :: A(*)

         CALL SUB2(A, N)
       END

       SUBROUTINE SUB2(A, N)
         USE TYPES
         TYPE(REC) A(*)

         PRINT *, A(:N)%A
       END

       PROGRAM MAIN
         USE TYPES
         CLASS(REC), ALLOCATABLE :: A(:)
         INTERFACE
           SUBROUTINE SUB1(A, N)
             USE TYPES
             CLASS(REC), INTENT(IN) :: A(*)
           END SUBROUTINE
         END INTERFACE

         ALLOCATE (A, SOURCE = (/(REC2(I, I+1), I = 1, 10)/))
         CALL SUB1(A, 10)
       END

-------------------------------------------------------------------

A member of Oracle's Fortran team questions whether the call in the
subroutine SUB1 is intended to be standard conforming.  At least
some implementations require explicit-shape and assumed-size
arguments to be contiguous.  Thus, as part of the code sequence
for the call of SUB2 in SUB1 must make a copy of the part of the
array A consisting of the elements of type REC.  Making that copy
requires knowing the number of elements that need to be copied.
The member of Oracle's Fortran team asserts, and I agree, that it is
counter-intuitive to require knowing the number of elements of an
assumed-size array.

James Xia of IBM demonstrated that IBM's implementation handles the
program as would be expected if it is standard conforming.  I have
compiled and run the program using some other compilers and none of
them produced the expected result.  The common result was

   1  2  2  3  3  4  4  5  5  6

Is the call of SUB2 in subroutine SUB1 intended to be standard
conforming?

Robert Corbett



More information about the J3 mailing list