(j3.2006) Interp request for GENERIC
Tom Clune
Thomas.L.Clune
Thu Mar 3 22:54:21 EST 2011
In the sample code below there are two derived types defined - Base
and Child, which EXTEND's Base. Base defines a GENERIC with two type-
bound procedures, and Child overrides those type bound procedures. On
two compilers, when the generic is invoked on an object of type child,
the Child's type-bound procedures are invoked, while one other the
parent's are invoked. The former makes more intuitive sense. The
statements on the subject in the extant F2003 books left me more
confused on this issue.
module ClassMod
implicit none
type Base
contains
procedure :: base_i
procedure :: base_r8
generic :: proc => base_i, base_r
end type Base
type, extends(Base) :: Child
integer :: i
real :: x
contains
procedure :: base_i => child_i
procedure :: base_r => child_r
end type Child
contains
subroutine base_i(this,i)
class(Base) :: this
integer :: i
write(6,*) 'executed base_i'
end subroutine base_i
subroutine base_r(this,x)
class(Base) :: this
real :: x
write(6,*) 'executed base_r'
end subroutine base_r
subroutine child_i(this,i)
class(Child) :: this
integer :: i
this%i = i
write(6,*) 'executed child_i'
end subroutine child_i
subroutine child_r(this,x)
class(Child) :: this
real :: x
this%x = x
write(6,*) 'executed child_r'
end subroutine child_r
end module ClassMod
program tryit
use ClassMod
implicit none
integer :: i
real :: x
type(Base) :: foo
type(Child) :: bar
i = 5
x = 20e0
write(6,*) 'calling Base:'
call foo%proc(i)
call foo%proc(x)
write(6,*) 'calling actual procedures:'
call bar%proc(i)
call bar%proc(x)
end program tryit
Thanks in advance,
- Tom
Thomas Clune
Software Integration and Visualization Office
NASA GSFC (610.3)
301-286-4635 (W) 301-286-1775 (F)
<Thomas.L.Clune at nasa.gov>
More information about the J3
mailing list