Derived type parameters (Fortran 2003)

A derived type is parameterized if the DERIVED_TYPE_statement has any type_param_names, or if it inherits any type parameter from its ancestor type. You can define the type parameters for the derived type.

Syntax of a type parameter definition

Read syntax diagramSkip visual syntax diagram
>>-INTEGER--+---------------+--,--+-KIND-+--::--type_param_decl_list-><
            '-kind_selector-'     '-LEN--'                             

kind_selector
Specifies the kind type parameter for the integer type. See the kind_selector section of INTEGER statement for syntax details.

type_param_decl

Read syntax diagramSkip visual syntax diagram
>>-type_param_name--+-----------------------------------+------><
                    '-=--scalar_int_initialization_expr-'   

Each type_param_name in a type_param_decl must match one of the type_param_name parameters listed in the DERIVED_TYPE_statement. Each type_param_name in the DERIVED_TYPE_statement must be specified once in a type_param_decl in the derived type definition.

A derived type parameter can be one of the following parameters.
  • It is a kind type parameter if it is declared with the KIND specifier.
  • It is a length type parameter if it is declared with the LEN specifier.
A derived type parameter can be used as a primary in a specification expression in the derived type definition. A kind type parameter can also be used as a primary in a constant expression in the derived type definition.

If a type_param_decl has a scalar_int_initialization_expr, the type parameter has a default value specified by the expression.

Example
TYPE general_point (k, dim)
  INTEGER, KIND :: k = selected_real_kind(6,70)
  INTEGER, LEN :: dim

  REAL(k) :: coordinates(dim)
END TYPE general_point
Type parameter order
Is the sequence of type parameters of a parameterized derived type. It is used for derived type specifiers (see Type Declaration) that do not use type parameter name keywords.
If a type is not an extended type, its type parameter order is the order of the type parameter list in the DERIVED_TYPE_statement. The type parameter order of an extended type consists of the type parameter order of its parent type, followed by any additional type parameters in the order of the type parameter list in its DERIVED_TYPE_statement.


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us