- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[fortran] module m_extAnd surely, it outputs
type:: base
integer:: b = Z'BBBBBBBB'
end type base
type, extends(base):: ext
integer:: e= Z'EEEEEEEE'
end type ext
end module m_ext
!=====================================
program PolyDummy
use m_ext
implicit none
! Variables
type(ext):: ex
! Body of PolyDummy
call PolyBase(ex%base)
call PolyBase(ex)
end program
!=====================================
subroutine PolyBase(bs)
use m_ext
class(base):: bs
select type(bs)
class is (base)
print*, "Base"
class is (ext)
print*, "Ext"
end select
end subroutine PolyBase
[/fortran]
[bash]Base
Ext[/bash]
But I'm wondering just how does this work, i.e. how is the information about type passed from the program to the subroutine? I don't see any hidden arguments, I don't see any "guard bytes" around type definition. I'm not particularly good with assembly to reverse-engineer the machine code of PolyBase (or at least, it's easier to ask).
Note that there is no explicit interface for PolyBase. Is it required? I suppose yes, but I purposefully omitted it to see if it would work without it. And Lord, it does.
I'm interested because I plan to use (or abuse :) ) polymorphic (CLASS) arguments in INTERFACEs to C functions. Those C functions need not deduce the passed type, but they shouldn't crash because Fortran passes some extra information in an unexpected place.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This program should not have worked. It only does if you have generated interface checking enabled and that is a bug. I will report it. Issue ID is DPD200151279.
An explicit interface is required when a dummy argument is polymorphic. The compiler passes a descriptior with type information that is then examined by SELECT TYPE.
I will mention that in the next major release (call it 12.0), we're going to require that you recompile sources that use CLASS as we have to significantly change the descriptor layout in order to accomodate finalizers and more.
The F2003 features will be documented in 12.0.

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