(j3.2006) ALLOCATE with MOLD: Default initializer and dynamic type
Tobias Burnus
burnus
Sun Jun 13 16:16:18 EDT 2010
Hello,
I have a question regarding ALLOCATE with MOLD where both the
source-expr is polymorphic - and, thus, the allocate-object is as well.
Executing the allocate statement, the allocate-object gets the same
dynamic type as the source-expr:
"if source-expr is specied, each allocate-object is allocated with the
dynamic type and type parameter
values of source-expr"
For SOURCE, it gets the value of the source-expr - but for MOLD it does
not. My interpretation is now that then the default-initialization of
components kicks in - namely the one of the dynamic type. Is my
interpretation correct?
The program below prints with one compiler:
a= 0 b= 0
though I had expected the answer to be
a= 1 b= 3
If the latter is correct: How do other vendors plan to handle this?
Adding another entry to the vtable? (Assuming that you also use a
vtable.) Or can something smarter be done?
Tobias
implicit none
type t
integer :: a = 1
end type t
type, extends(t) :: t2
integer :: b = 3
end type t2
class(t), allocatable :: x, y
allocate (t2 :: y)
select type (y)
type is (t2)
y%a = 44
y%b = 55
end select
allocate ( x, mold=y)
select type (x)
type is (t2)
print *, 'a=', x%a, ' b=', x%b
end select
end
More information about the J3
mailing list