5.1 Type Declaration Statements

A type declaration statement explicitly specifies the properties of data objects or functions.

The general form of a type declaration statement follows:

type [[, att]... ::] v [/c-list/] [, v [/c-list/]]...

type
Is one of the following data type specifiers:

BYTE  DOUBLE COMPLEX 
INTEGER[([KIND=]k)]  CHARACTER[([LEN=]n)[,[KIND=]k]] 
REAL[([KIND=]k)]  LOGICAL[([KIND=]k)] 
DOUBLE PRECISION  TYPE (derived-type-name) 
COMPLEX[([KIND=]k)]   

In the optional kind selector "([KIND=]k)", k is the kind parameter. It must be an acceptable kind parameter for that data type. If the kind selector is not present, entities declared are of default type. (For a list of the valid noncharacter data types, see Table 5-2.)

Kind parameters for intrinsic numeric and logical data types can also be specified using the *n format, where n is the length (in bytes) of the entity; for example, INTEGER*4.

att
Is one of the following attribute specifiers:

ALLOCATABLE   (Section 5.2)   POINTER  (Section 5.15
AUTOMATIC  (Section 5.3)   PRIVATE 1  (Section 5.16
DIMENSION  (Section 5.6)   PUBLIC 1  (Section 5.16
EXTERNAL  (Section 5.8)   SAVE  (Section 5.17
INTENT  (Section 5.10)   STATIC  (Section 5.3
INTRINSIC  (Section 5.11)  TARGET  (Section 5.18
OPTIONAL  (Section 5.13)   VOLATILE  (Section 5.19
PARAMETER  (Section 5.14    
1 These are access specifiers.

v
Is the name of a data object or function. It can optionally be followed by:

A function name must be the name of an intrinsic function, external function, function dummy procedure, or statement function.

c-list
Is a list of constants, as in a DATA statement. If v is the name of a constant or an initialization expression, the c-list cannot be present.

The c-list cannot specify more than one value unless it initializes an array. When initializing an array, the c-list must contain a value for every element in the array.

Rules and Behavior

Type declaration statements must precede all executable statements.

In most cases, a type declaration statement overrides (or confirms) the implicit type of an entity. However, a variable that appears in a DATA statement and is typed implicitly can appear in a subsequent type declaration only if that declaration confirms the implicit typing.

The double colon separator (::) is required only if the declaration contains an attribute specifier or initialization; otherwise it is optional.

If att appears, c-list cannot be specified; for example:

INTEGER I /2/                ! Valid
INTEGER, SAVE :: I /2/       ! Invalid

The same attribute must not appear more than once in a given type declaration statement, and an entity cannot be given the same attribute more than once in a scoping unit.

If the PARAMETER attribute is specified, the declaration must contain an initialization expression.

If => NULL( ) is specified for a pointer, its initial association status is disassociated.

A variable (or variable subobject) can only be initialized once in an executable program.

If a declaration contains an initialization expression, but no PARAMETER attribute is specified, the object is a variable whose value is initially defined. The object becomes defined with the value determined from the initialization expression according to the rules of intrinsic assignment.

The presence of initialization implies that the name of the object is saved, except for objects in named common blocks or objects with the PARAMETER attribute.

The following objects cannot be initialized in a type declaration statement:

An object can have more than one attribute. Table 5-1 lists the compatible attributes.

Table 5-1 Compatible Attributes

Attribute  Compatible with: 
ALLOCATABLE  AUTOMATIC, DIMENSION1, PRIVATE, PUBLIC, SAVE, STATIC, TARGET, VOLATILE 
AUTOMATIC  ALLOCATABLE, DIMENSION, POINTER, TARGET, VOLATILE 
DIMENSION  ALLOCATABLE, AUTOMATIC, INTENT, OPTIONAL, PARAMETER, POINTER, PRIVATE, PUBLIC, SAVE, STATIC, TARGET, VOLATILE 
EXTERNAL  OPTIONAL, PRIVATE, PUBLIC 
INTENT  DIMENSION, OPTIONAL, TARGET, VOLATILE 
INTRINSIC  PRIVATE, PUBLIC 
OPTIONAL  DIMENSION, EXTERNAL, INTENT, POINTER, TARGET, VOLATILE 
PARAMETER  DIMENSION, PRIVATE, PUBLIC 
POINTER  AUTOMATIC, DIMENSION1, OPTIONAL, PRIVATE, PUBLIC, SAVE, STATIC, VOLATILE 
PRIVATE  ALLOCATABLE, DIMENSION, EXTERNAL, INTRINSIC, PARAMETER, POINTER, SAVE, STATIC, TARGET, VOLATILE 
PUBLIC  ALLOCATABLE, DIMENSION, EXTERNAL, INTRINSIC, PARAMETER, POINTER, SAVE, STATIC, TARGET, VOLATILE 
SAVE  ALLOCATABLE, DIMENSION, POINTER, PRIVATE, PUBLIC, STATIC, TARGET, VOLATILE 
STATIC  ALLOCATABLE, DIMENSION, POINTER, PRIVATE, PUBLIC, SAVE, TARGET, VOLATILE 
TARGET  ALLOCATABLE, AUTOMATIC, DIMENSION, INTENT, OPTIONAL, PRIVATE, PUBLIC, SAVE, STATIC, VOLATILE 
VOLATILE  ALLOCATABLE, AUTOMATIC, DIMENSION, INTENT, OPTIONAL, POINTER, PRIVATE, PUBLIC, SAVE, STATIC, TARGET 
1 With deferred shape

Examples

The following show valid type declaration statements:

DOUBLE PRECISION B(6)
INTEGER(KIND=2) I
REAL(KIND=4) X, Y
REAL(4) X, Y
LOGICAL, DIMENSION(10,10) :: ARRAY_A, ARRAY_B
INTEGER, PARAMETER :: SMALLEST = SELECTED_REAL_KIND(6, 70)
REAL(KIND (0.0)) M
COMPLEX(KIND=8) :: D
TYPE(EMPLOYEE) :: MANAGER
REAL, INTRINSIC :: COS
CHARACTER(15) PROMPT
CHARACTER*12, SAVE :: HELLO_MSG
INTEGER COUNT, MATRIX(4,4), SUM
LOGICAL*2 SWITCH
REAL :: X = 2.0

TYPE (NUM), POINTER :: FIRST => NULL()

For More Information:


Previous Page Next Page Table of Contents