- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 withOmittedfield 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
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page