Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 9/08/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Deferred-Length Type Parameters for Parameterized Derived Types

Similar to deferred character lengths and deferred array bounds, the length type parameters of a derived type can be deferred. A deferred-length type parameter is specified when type-param-value in the type-param-spec is a colon (":").

A derived type object with a deferred-length type parameter must have an ALLOCATABLE or POINTER attribute. The value of a deferred type parameter is deferred until allocation or association.

When the dummy argument is allocatable or a pointer, the actual argument must have deferred the same type parameters as the dummy argument.

TYPE(matrix(k=KIND(0.0), d1= :, d2= :)), pointer :: my_mtrx_ptr, my_mtrx_alloc
TYPE(matrix(KIND(0.0), 100, 200)), target :: my_mtrx_tgt
TYPE(matrix(KIND(0.0), 1, 2)) :: my_mtrx_src

my_mtrx_ptr => my_mtrx_tgt   ! Gets values from target 
! my_mtrx_ptr has d1= 100 and d2 = 200.

ALLOCATE(matrix(KIND(0.0), 10, 20) :: my_mtrx_alloc)  ! Gets values from allocation
! my_mtrx_alloc has d1=10 and d2=20
DEALLOCATE(my_mtrx_alloc)

ALLOCATE(my_mtrx_alloc, source=my_mtrx_src)  ! Gets values from allocation
! my_mtrx_alloc has d1=1 and d2=2

All non-deferred type parameter values of the declared type of the pointer object that correspond to non-deferred type parameters of the pointer target must agree. If a pointer object has non-deferred type parameters that correspond to deferred type parameters of a pointer target, the pointer target must not have undefined association status.

Deferred type parameters of functions, including function procedure pointers, have no values. Instead, they indicate that those type parameters of the function result will be determined by execution of the function, if it returns an allocated allocatable result or an associated pointer result.

If an ALLOCATE statement specifies a derived type object with deferred type parameters, it must either have the derived-type specification or a source-expr (a scalar expression). The kind type parameter values and the non-deferred length type parameter values in the derived-type specification or source-expr must be the same as the corresponding values of the derived type object.

TYPE(matrix(k=KIND(0.0), d1= 100, d2= :)), pointer :: my_mtrx_alloc
TYPE(matrix(KIND(0.0), 1, 2)) :: my_mtrx_src

ALLOCATE(my_mtrx_alloc, source=my_mtrx_src)  ! Illegal - d1 is not deferred
! my_mtrx_src must have the same value for d1