(j3.2006) question about IMPORT and derived types
Bill Long
longb
Wed Apr 8 13:15:29 EDT 2009
I tried three compilers - PGI and Pathscale both give errors. The Cray
compiler compiled it without any errors, and gave no messages with the
standard-conformance checking enabled.
Cheers,
Bill
Robert Corbett wrote:
> The following program fails to compile with every compiler I used
> to compile it including Sun's:
>
> MODULE MOD
> TYPE T1
> SEQUENCE
> TYPE(T2), POINTER :: P
> END TYPE
> TYPE T2
> SEQUENCE
> INTEGER I
> END TYPE
> END
>
> PROGRAM MAIN
> USE MOD, T3 => T1, T4 => T2
> TYPE T1
> SEQUENCE
> TYPE(T2), POINTER :: P
> END TYPE
> INTERFACE SUBR
> SUBROUTINE SUBR1(X)
> IMPORT T3
> TYPE(T3) X
> END SUBROUTINE
> SUBROUTINE SUBR2(X)
> IMPORT T1
> TYPE(T1) X
> END SUBROUTINE
> END INTERFACE
> TYPE T2
> SEQUENCE
> REAL X
> END TYPE
> END
>
> SUBROUTINE SUBR1(X)
> USE MOD
> TYPE(T1) X
> END
>
> SUBROUTINE SUBR2(X)
> TYPE T1
> SEQUENCE
> TYPE(T2), POINTER :: P
> END TYPE
> TYPE T2
> SEQUENCE
> REAL X
> END TYPE
> TYPE(T1) X
> END
>
> The problem, of course, is the definition of the derived
> type T2 following the interface block. Section 12.3.2.1
> of the Fortran 2003 standard says regarding the IMPORT
> statement
>
> If an entity that is made accessible by this means
> is accessed by host association and is defined in
> the host scoping unit, it shall be explicitly
> declared prior to the interface body.
>
> That clearly requires T1 and T3 to be defined prior to the
> interface body, but it does not require T2 to be defined
> prior to the interface body. Therefore, the program appears
> to be standard conforming. Have I missed something?
>
> Bob Corbett
> _______________________________________________
> J3 mailing list
> J3 at j3-fortran.org
> http://j3-fortran.org/mailman/listinfo/j3
>
--
Bill Long longb at cray.com
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc., 1340 Mendota Heights Rd., Mendota Heights, MN, 55120
More information about the J3
mailing list