Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28767 Discussions

Generic interface with the same name as a derived type

Olsen__Oystein
Beginner
407 Views
If I understand the standard correctly then the following program should work
[bash]MODULE DType
  IMPLICIT NONE
  PUBLIC

  INTEGER, PARAMETER :: I4B = SELECTED_INT_KIND(9)
  !INTEGER, PARAMETER  :: WP = SELECTED_REAL_KIND(6,37)
  !INTEGER, PARAMETER  :: WP = SELECTED_REAL_KIND(15,307)
  INTEGER, PARAMETER  :: WP = SELECTED_REAL_KIND(32,4931)

  TYPE JD
     INTEGER(I4B) :: JDN = 2451545
     REAL(WP)     :: FD = 0.0_WP, tmp
   CONTAINS
     GENERIC                  :: ASSIGNMENT(=) => setJD
     PROCEDURE, PRIVATE, PASS :: setJD
  END TYPE JD

  INTERFACE JD
     MODULE PROCEDURE constructor
  END INTERFACE JD

CONTAINS
  FUNCTION constructor(n, f)
    INTEGER(I4B), INTENT(IN) :: n
    REAL(WP), INTENT(IN)     :: f
    TYPE(JD)                 :: constructor
    
    constructor%JDN = n
    constructor%FD  = f
    RETURN
  END FUNCTION constructor

  SUBROUTINE setJD(a, b)
    CLASS(JD), INTENT(INOUT) :: a
    TYPE(JD), INTENT(IN)     :: b
    
    a%JDN = b%JDN
    a%FD = b%FD 
  END SUBROUTINE setJD
END MODULE DType

PROGRAM test_dtype
  USE DType
  IMPLICIT NONE
  
  TYPE(JD) :: a, c

  a = constructor(2451546, 0.5_WP)
  WRITE(*,*) a%JDN, a%FD

  c = JD(2451546, 0.5_WP)
  WRITE(*,*) c%JDN, c%FD
END PROGRAM test_dtype
[/bash]
Compiling the program with latest compiler on openSUSE 11.4 fails with
Omittedfield is not initialized. Field initialization missing: [TMP]".
c = JD(2451546, 0.5_WP)
Hence, it looks like the compiler ignores the interface definition, while the release notes does say that it supports generic interface with the same name as a derived type.
Regards Oystein
0 Kudos
1 Reply
Steven_L_Intel1
Employee
407 Views
See this thread for an earlier discussion of this. I did some more reading of the standard and am now puzzled at the wording. I have a query in about this.
0 Kudos
Reply