HP Fortran Programmer's Reference (September 2007)

Data types and data objects
Derived types
Chapter 5126
If
parent-name
and
comp-name
are arrays, each can be followed by a
section-subscript-list
enclosed in parentheses. See “Array sections” on page 68 for
information about the syntax of
section-subscript-list
. The Standard imposes certain
restrictions on structure component references that are array-valued, as described in
Array-valued structure component references” on page 72.
If the definition of a derived type contains a component that is of the same derived type, the
component must have the POINTER attribute. The following example defines the derived type
node, which includes a component (next) of the same derived type:
TYPE node ! for use in a singly linked list
INTEGER :: value
TYPE(node), POINTER :: next ! must have the POINTER attribute
END TYPE node
Declaring a derived type-object
To declare an object of derived type, use the TYPE statement, as follows:
TYPE (
type-name
) [[,
attrib-list
] :: ]
entity-list
where
type-name
,
attrib-list
, and
entity-list
all have the same meaning as in a type
declaration statement that is used to declare an object of an intrinsic type; see “Type
declaration for intrinsic types” on page 109.
Structure constructor
A structure constructor constructs a scalar value of derived type. The value is constructed of a
sequence of values for each component of the type. The syntax of a structure constructor is:
type-name
(
expression-list
)
type-name
is the name of the derived type. The name must have been previously
defined.
expression-list
is a comma-separated list of expressions that must agree in number, order,
and rank with the components in
type-name
. For information about
expressions, see “Expressions” on page 85 and “Special forms of expression”
on page 92.
The following restrictions apply to the use of the structure constructor:
If a component is of derived type, an embedded structure constructor must be used to
specify a value for the derived-type component.