LF Fortran 95

TYPE Statement

Description

The TYPE statement defines a derived type, and declares entities having a derived type.

Syntax

(Definition)

TYPE [, access-spec] [::] type-name

(Declaration)

TYPE (type-name) [, attribute-list] [::] entity [, entity] ...

Where:

access-spec is PUBLIC or PRIVATE

type-name is the name of the derived type being defined.

attribute-list is a comma-separated list from the following attributes:

PARAMETER, ALLOCATABLE, DIMENSION(array-spec), EXTERNAL, INTENT(IN) or INTENT(OUT) or INTENT(IN OUT), PUBLIC or PRIVATE, INTRINSIC, OPTIONAL, POINTER, SAVE, TARGET, VOLATILE, DLL_EXPORT or DLL_IMPORT or ML_EXTERNAL.

entity is entity-name [(array-spec)] [=initialization-expr] or func-name [(array-spec)]

array-spec is an array specification.

initialization-expr is an expression that can be evaluated at compile time.

entity-name is the name of an entity being declared.

func-name is the name of a function being declared.

Remarks

access-spec is permitted only if the derived type definition is within the specification part of a module.

If a component of a derived type is of a type declared to be private, either the definition must contain the PRIVATE statement or the derived type must be private.

type-name must not be the name of an intrinsic type nor of another accessible derived type name.

func-name must be the name of an external, intrinsic, or statement function, or a function dummy procedure.

The =initialization-expr must appear if the statement contains a PARAMETER attribute.

If =initialization-expr appears, a double colon must appear before the list of entities. Each entity has the SAVE attribute, unless it is in a named common block.

The =initialization-expr must not appear if entity-name is a dummy argument, a function result, an object in a named common block unless the type declaration is in a block data program unit, an object in blank common, an allocatable array, a pointer, an external name, an intrinsic name, or an automatic object.

If an array or function with an array result is declared with the POINTER attribute, it must have a deferred shape.

If an array is declared with the ALLOCATABLE attribute, it must have a deferred shape.

If an array or function with an array result does not have the POINTER or the ALLOCATABLE attribute, it must be specified with an explicit shape.

If the POINTER attribute is specified, the TARGET, INTENT, EXTERNAL, or INTRINSIC attributes must not be specified.

If the TARGET attribute is specified, the POINTER, EXTERNAL, INTRINSIC, or PARAMETER attributes must not be specified.

The PARAMETER attribute cannot be specified for dummy arguments, pointers, allocatable arrays, functions, or objects in a common block.

The INTENT(IN), INTENT(OUT), INTENT(IN OUT), and OPTIONAL attributes can be specified only for dummy arguments.

An entity may not have the PUBLIC attribute if its type has the PRIVATE attribute.

The SAVE attribute must not be specified for an object that is in a common block, a dummy argument, a procedure, a function result, or an automatic data object.

An entity must not have the EXTERNAL or INTRINSIC attribute specified unless it is a function.

A subprogram must not have the EXTERNAL attribute if it has the INTRINSIC attribute.

An entity having the ALLOCATABLE attribute cannot be a dummy argument or a function result.

An array must not have both the ALLOCATABLE attribute and the POINTER attribute.

If an entity has the VOLATILE attribute, it cannot have the PARAMETER, INTRINSIC, EXTERNAL, or INTENT(IN) attributes.

An entity may not be given the same attribute more than once in a scoping unit.

Example

type zee ! type definition sequence real :: a,b integer :: i end type zee type (zee) :: a,b,c(2,2) ! type declaration type (zee) :: e=zee(2.,3.5,-1) ! with initialization