Intel® Fortran Compiler 16.0 User and Reference Guide

Parameterized Derived-Type Declarations

A derived type is parameterized if the derived TYPE statement has type parameter names or it inherits any type parameters.

The type parameters must be listed in the type definition. You must specify a type and you must specify whether they are KIND or LEN parameters. A type parameter definition takes the following form:

INTEGER [kind-selector], type-param-attr-spec :: type-param-decl-list

kind-selector

(Optional) Is one of the kind type parameter numbers allowed for integer data types. For more information, see Integer Data Types.

If you do not specify kind-selector, default integer kind is assumed.

type-param-attr-spec

Is KIND or LEN.

type-param-decl-list

Is one or more of the following separated by commas:

type-param-name [= init-spec]

type-param-name

Is the name of the type parameter. Each type-param-name must match one of the type-param-name parameters listed in the derived TYPE statement.

init-spec

(Optional) Must be a scalar integer initialization expression.

If init-spec is specified, the type parameter has a default value that is specified by the expression init-spec. If necessary, the value of init-spec is converted to an integer value of the same kind as the type parameter in accordance with the rules of intrinsic assignment.

Explicit values for the type parameters are normally specified when an object of the parameter type is declared.

Within the type definition, kind type parameters may be used in constant expressions and specification expressions. Length type parameters may be used in specification expressions but not in constant expressions. The type parameters need not be used anywhere in the derived type.

Kind type parameters also participate in generic resolution Unambiguous Generic Procedure References. A single generic can include two specific procedures that have interfaces distinguished only by the value of a kind type parameter of a dummy argument.

An explicit interface is required if a parameterized derived type is used as a dummy argument. In a SELECT TYPE construct, the kind type parameter values of a type guard statement must be the same as those of the dynamic type of the selector. A BIND(C) type and a SEQUENCE type must not have type parameters.

Advantages to Using This Feature

Adding type parameters to a derived type allows you to declare objects of similar types that differ depending on the kind and length parameters used in the object declaration. For example, the type definition matrix below has two type parameters, a kind parameter k and a length parameter b.

TYPE matrix ( k, b )
  INTEGER,     KIND :: k = 4
  INTEGER (8), LEN  :: b
  REAL (k)          :: element (b,b)
END TYPE matrix

The user can declare a matrix named square of 10 by 10 elements of REAL(8) with the following declaration:

TYPE (matrix (8, 10)) :: square

The user can declare another matrix named big_square of 100 by 100 elements of REAL(4) with the following declaration:

TYPE (matrix (10)) :: square    ! k defaults to 4

See Also