(j3.2006) ALLOCATE with MOLD: Default initializer and dynamic type
Bill Long
longb
Mon Jun 14 00:45:33 EDT 2010
Hi Tobias,
Tobias Burnus wrote:
> 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?
>
Yes. The relevant wording in 10-007 is at [454:28-29] list item (19)
"Allocation of an object that has a nonpointer default-initialized
subcomponent, except by an ALLOCATE statement with a SOURCE= specifier,
causes that subcomponent to become defined."
Since the allocate in your example below does not have a SOURCE=
specifier, the initialization should occur.
Cheers,
Bill
> 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
> _______________________________________________
> J3 mailing list
> J3 at j3-fortran.org
> http://j3-fortran.org/mailman/listinfo/j3
--
Bill Long longb at cray.com
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101
More information about the J3
mailing list