TYPE
Purpose
The TYPE statement is the first statement of a derived type definition.
Syntax
- type_name
- is the name of the derived type
- extends_spec (Fortran 2003)
- is
- type_param_name (Fortran 2003)
- is the name of a type parameter. For more information, see Derived type parameters (Fortran 2003).
Rules
The same
type attribute can not occur more than once on the same TYPE statement.
You can specify the PRIVATE or PUBLIC attribute only if the derived type definition is within the specification part of a module. A derived type definition can be PRIVATE or PUBLIC, not both.
- The type name and any
type parameter names
for this derived type. - Structure constructors for the type.
- Any procedure that has a dummy argument or function result of the type.
The type_name must not be the same as the name of any intrinsic type, except BYTE and DOUBLECOMPLEX. The type_name must also not be the name of any other accessible derived type.
BIND(C) explicitly defines the
Fortran derived type as interoperable with a C type. The components must be of interoperable types.
(See Interoperability of types for additional information.) A derived type
with the BIND attribute cannot be a SEQUENCE
type. A component of a derived type with the BIND attribute must have
interoperable type and type parameters, and cannot have the POINTER or
ALLOCATABLE attribute. If EXTENDS is specified,
the type must not have the BIND(C) attribute.
The parent_type_name must be an accessible extensible type. For more information about extensible type, see Extensible derived types (Fortran 2003).
You can only specify the ABSTRACT attribute for an extensible type.
If EXTENDS is specified, SEQUENCE cannot appear for that type.
If EXTENDS is specified and the type being defined has an ultimate component of type LOCK TYPE from the ISO_FORTRAN_ENV intrinsic module, its parent type must have an ultimate component of type LOCK TYPE.
If type parameter names are specified, they must be unique in this type (including any
ancestors). Type parameter declarations are required for each name. For details, see Derived type parameters (Fortran 2003).
If the corresponding END TYPE statement specifies a name, it must be the same as type_name.
Examples
MODULE ABC
TYPE, PRIVATE :: SYSTEM ! Derived type SYSTEM can only be accessed
SEQUENCE ! within module ABC
REAL :: PRIMARY
REAL :: SECONDARY
CHARACTER(20), DIMENSION(5) :: STAFF
END TYPE
END MODULE
TYPE MULTIDIM (K,NDIMS)
INTEGER, KIND :: K
INTEGER, LEN :: NDIMS
REAL(K) :: POS(NDIMS)
END TYPE MULTIDIM
TYPE, EXTENDS(MULTIDIM) :: NAMED_MULTI (L)
INTEGER, LEN :: L
CHARACTER(L) :: NAME
END TYPE NAMED_MULTI
