(j3.2006) question about deallocation
Bill Long
longb at cray.com
Sat Mar 28 11:05:26 EDT 2009
Robert Corbett wrote:
> Bill Long wrote:
>>
>> Robert Corbett wrote:
>>
>>> Consider the code fragment
>>>
>>> MODULE M
>>> . . .
>>> TYPE BASE
>>> INTEGER I
>>> CONTAINS
>>> FINAL SUBR1
>>> END TYPE
>>> TYPE, EXTENDS(BASE) :: EXTENDED
>>> CONTAINS
>>> FINAL SUBR2
>>> END TYPE
>>> . . .
>>> END MODULE
>>>
>>> PROGRAM MAIN
>>> USE M
>>> TYPE(EXTENDED), POINTER :: P
>>> TYPE(BASE), POINTER :: Q
>>> . . .
>>> ALLOCATE(P)
>>> Q => P%BASE
>>> . . .
>>> DEALLOCATE(Q)
>>> . . .
>>> END
>>>
>>> Is the DEALLOCATE statement standard conforming?
>>
>>
>> The extended type does not add any components, so it looks OK to me.
>
> Your answer is consistent with what I have heard from members of the
> committee regarding similar cases, as I noted in my response to
> Reinhold Bader.
>
>>> If so,
>>> are both final subroutines invoked, or is only SUBR1
>>> invoked?
>>
>>
>> The type of the object being deallocated is BASE, and a final routine
>> is bound to the type, so I would say SUBR1 (only) is executed.
>
> Your answer here is what I think a literal reading of the standard
> would yield. I fear that interpretation will prove troublesome for
> users.
I fear that final subroutines, in general, will prove troublesome for
users. In this case, Q is not polymorphic and has only one possible
type. The type EXTENDED is nowhere visible to the finalization process
for Q. I don't see how SUBR2 would be (or should be) found in this case.
Cheers,
Bill
>
> Bob Corbett
--
Bill Long longb at cray.com
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc., 1340 Mendota Heights Rd., Mendota Heights, MN, 55120
More information about the J3
mailing list