(j3.2006) Finalization ordering question

Jim Xia jimxia
Fri Oct 12 11:31:24 EDT 2007

> Jim Xia wrote:
> > That's how the standard defines the sequence of finalizations of an 
> > array of objects of extended type.  I wouldn't think of "efficiency" 
> > an issue when finalizations are involved.
> Sure, but this does mean we should have rules that require 
> less-efficient code! Bill's suggested reordering makes sense to me, in 
> fact, that is how I would have implemented it: finalize one element 
> completely and then move on to the next one (after all, an array is just 

> a collection of scalars and requiring a specific order of the elements 
> seems contrary to what we usually do). There may be some other reason 
> why things are written the way they are...Malcolm or Kurt would know :-)
> Aleks

I'm more concerned about the safety issues with finalization at this 
point.  I think J3 made a mistake in passing F03/0062 interp to finalize 
an array constructor -- I was against this proposal from day one when the 
question first surfaced.  If you look at the lessons from C++ destructor, 
then you know why I'm concerned.  There was a time in C++ world people 
talked a lot about "the big three things": default constructor, copy 
constructor and assignment.  All actually are tied with destructor.  The 
essence is that the language must provide tools for overriding 
constructors and assignments in order for the destructors to be used 
safely.  In FORTRAN we have such tools for structure constructors and 
assignments, but we don't have overriding tools for array constructors. 
This will cause unsafe "features" in the language and there is no easy way 
to get around with.  Say you have 2 objects, a and b, of a derived type X 
having a pointer component.  So you add both scalar and rank-one array 
final routines for the type in order to manage memory 
allocation/deallocation of its pointer component.  Then code like "call 
sub([a, b])" will certainly yield surprise to you: your objects a and b 
are modified after the subroutine call thanks to the finalization of the 
array object produced by array constructor.  Because the nature of 
"shallow copying" for pointer components in constructing an array using 
array constructor, it is unsafe to call for a finalization for it unless 
you provide a user a way to override its behavior.  Currently we don't 
have this tool.

Anyway my feeling is FORTRAN users not familiar with C++ would likely find 
the finalization thing difficult to work with.  And in fact he'll likely 
have to re-learn the lessons already learnt from similar features in other 
languages, such as destructors in C++.


Jim Xia

XL Fortran Compiler Testing
IBM Toronto Lab at 8200 Warden Ave.
Phone (905) 413-3444  Tie-line 969-3444
D2/NAH/8200 /MKM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://j3-fortran.org/pipermail/j3/attachments/20071012/4d84ca81/attachment.html 

More information about the J3 mailing list