Component definition statement

Standard: F77 F90 F95 F2003 F2008 Example program


<Syntax>

A component definition statement is either a data component definition or a procedure component definition.

data-component-def-stmt ::= type [ [ , attr ]... :: ] entity-decl-list

attr ::= ALLOCATABLE
| CODIMENSION '[' coarray-spec ']'
| CONTIGUOUS
| DIMENSION ( array-spec )
| POINTER
| PRIVATE
| PUBLIC

proc-component-def-stmt ::= PROCEDURE ( [ interface ] ) , proc-component-attr-list :: proc-component-decl-list

If ALLOCATABLE or POINTER is specified for a data component, any array-spec must be deferred-shape; otherwise any array-spec must be explicit-shape and have constant bounds.

The PUBLIC and PRIVATE attributes are only permitted in the specification part of a module.

A procedure component definition specifies an object-bound procedure; refer to that page for full syntax and semantics.

The notation '[' and ']' in the CODIMENSION attribute means the actual square bracket characters appear in the program, i.e. they are not BNF optionality brackets. The CODIMENSION attribute is only allowed in conjunction with ALLOCATABLE, and therefore the coarray-spec must be a deferred-coshape-spec.

<Semantics>

This statement declares one or more components of a derived type. If an entity-decl contains an initialisation (“= expression” or “=> NULL()”), it defines the default value for that component; this is called default initialisation. Default initialisation is applied whenever an object of the type is created, and for INTENT(OUT) arguments. Default initialisation also allows the value for such a component to be omitted in the structure constructor; the result of the constructor will have the default value for that component.

In Fortran 2003, a component may be explicitly declared to be PUBLIC or PRIVATE; otherwise, a component is PRIVATE if the component definition statements are preceded by a PRIVATE statement, and PUBLIC otherwise. A PRIVATE component cannot be accessed from outside the module that defines the type.

In Fortran 2008, an array pointer component can be declared to be contiguous. Such a pointer is only permitted to be associated with a contiguous target.

<Related>

ALLOCATABLE attribute, Attributes, CODIMENSION attribute, CONTIGUOUS attribute, Derived Type Definition, DIMENSION attribute, END TYPE statement, Entity declaration list, Object-bound procedure, POINTER attribute, PRIVATE attribute, PUBLIC attribute, TYPE statement