(j3.2006) Finalizing subroutines question

Tobias Burnus burnus
Fri May 23 11:00:45 EDT 2008


Hello,

This came up when implementing FINAL in gfortran. (Found by Daniel 
Kraft, who works on it.)

In Fortran 2003 and 2008 CD one finds:

"C473 (R454) A final-subroutine-name shall be the name of a module 
procedure with exactly one dummy argument. That argument shall be 
nonoptional and shall be a nonpointer, nonallocatable, nonpolymorphic 
variable of the derived type being defined. All length type parameters 
of the dummy argument shall be assumed. The dummy argument shall not be 
INTENT(OUT)."

This implies that the following dummy arguments are all valid for the 
final subroutine (chose one at a time):

type(t) :: x(:)
type(t) :: x(*)
type(t) :: x(5)

Assuming that one has:

subroutine t_finalize(x)
  type(t) :: x(100)
end subroutine

and uses

type(t) :: myT(5)

Does this mean that on finalizing "t_finalize" is called? According to 
4.5.5.1:

"If the dynamic type of the entity has a final subroutine whose dummy 
argument has the same kind type parameters and rank as the entity being 
finalized, it is called with the entity as an actual argument."

I think this applies here. Am I misreading something or is this indeed 
the case? (If I could choose, I'd liked that the dummy argument is 
required to have either a scalar or has assumed shape.)

Tobias



More information about the J3 mailing list