(j3.2006) FINAL subroutines with explicit/assumed-size arrays

Bill Long longb
Mon May 7 17:10:56 EDT 2012



On 5/7/12 3:32 PM, Tobias Burnus wrote:
> Dear all,
>
> when looking at the FINAL, I got the impression that not only
> assumed-shape arrays are allowed but also explicit-size and assumed-size
> arrays.
>

Allocatable and pointer arrays are also allowed.  Finalization is more 
about the type of the object than whether it is an array or scalar. 
Assumed-size arrays would be problematic, but they are always dummy 
arguments and the combination of assumed-shape, INTENT(OUT), and having 
a type with a FINAL subroutine is not allowed (C534).


> However, that only makes sense, if all arrays of a type have the same
> size (per given rank) , or one passes the array size in a very indirect
> way (e.g. module variable) - or if one ignores the data completely or
> partially (e.g. using always only the first array element).
>

Elemental FINAL subroutines are allowed (and handy).  They are useful in 
accommodating multiple ranks and sizes of actual arguments.


> Hence, is the following program valid? If not, why? If yes, was it
> intended to valid - and, if not, does it make sense to fill an IR?
>

Seems OK.

Cheers,
Bill


>
> module test
> type t
> contains
> final :: fin
> end type t
> contains
> subroutine fin(x)
> type(t), intent(inout) :: x(3)
> ! or alternatively: "(2)" or "(*)" or "(4)"
> end subroutine fin
> end module test
>
> subroutine useIt()
> use test
> type(t) :: y(3)
> end subroutine useIt
>
> call useIt()
> end
>
>
> Tobias
>
> PS: The main FINAL constraint is the following:
>
> C480 (R452) 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
> have the INTENT (OUT) or VALUE attribute.
> _______________________________________________
> 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