- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
While using object-oriented programming in FORTRAN, I want to implement the user-defined IO for the derived type and its extended type. The sample code is
module test implicit none type :: base contains procedure :: ReadBase generic :: read(unformatted) => ReadBase end type base type, extends(base) :: derived contains procedure :: ReadDerived generic :: read(unformatted) => ReadDerived end type derived contains subroutine ReadBase(dtv,unit,stat,msg) implicit none class(base) :: dtv integer :: unit, stat character(*) :: msg end subroutine ReadBase subroutine ReadDerived(dtv,unit,stat,msg) implicit none class(derived) :: dtv integer :: unit, stat character(*) :: msg end subroutine ReadDerived end module test
After compiling, the error #8638 occurred, like this,
error #8638: The type/rank signature for arguments of this specific subroutine is identical to another specific subroutine that shares the same defined I/O. [READBASE]
Does anyone have a clue to resolve this problem?
Best wishes,
Rubin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are declaring a totally separate specific binding called ReadDerived in the extension type, but what you actually want to do is override the existing binding.
Type, extends (base) :: derived ... Contains Procedure :: ReadBase => ReadDerived End type derived ...
No need for another binding, no need to try and extend the generic binding with another specific. You just want a different procedure selected for the particular specific binding based on the dynamic type of the relevant object.
(The compiler resolves a generic binding to a specific binding at compile time based on the declared type of the relevant object(s). That specific binding is then resolved to a particular specific procedure at runtime based on the dynamic type of the relevant object. UDDTIO isn't anything special in this regard.)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are declaring a totally separate specific binding called ReadDerived in the extension type, but what you actually want to do is override the existing binding.
Type, extends (base) :: derived ... Contains Procedure :: ReadBase => ReadDerived End type derived ...
No need for another binding, no need to try and extend the generic binding with another specific. You just want a different procedure selected for the particular specific binding based on the dynamic type of the relevant object.
(The compiler resolves a generic binding to a specific binding at compile time based on the declared type of the relevant object(s). That specific binding is then resolved to a particular specific procedure at runtime based on the dynamic type of the relevant object. UDDTIO isn't anything special in this regard.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
IanH,
Excellent, Thank you very much.
Best wishes,
Rubin

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page