Statement: Explicitly specifies the properties of data objects or functions.
Syntax
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.
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.
See each data type for further information on that type.
ALLOCATABLE | INTRINSIC | PUBLIC 1 | |
AUTOMATIC | OPTIONAL | SAVE | |
DIMENSION | PARAMETER | STATIC | |
EXTERNAL | POINTER | TARGET | |
INTENT | PRIVATE 1 | VOLATILE | |
1 These are access specifiers. |
You can also declare any attribute separately as a statement.
In a function declaration, an array must be a deferred-shape array if it has the POINTER attribute; otherwise, it must be an explicit-shape array.
A function name must be the name of an intrinsic function, external function, function dummy procedure, or statement function.
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. The following table lists the compatible attributes:
Attribute | Compatible with: |
---|---|
ALLOCATABLE | AUTOMATIC, DIMENSION 1, 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, DIMENSION 1, 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 |
Compatibility
CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB
See Also: CHARACTER, COMPLEX, Derived Type, DOUBLE COMPLEX, DOUBLE PRECISION, INTEGER, LOGICAL, REAL, IMPLICIT, RECORD, STRUCTURE...END STRUCTURE, TYPE, Type Declaration Statements
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()
The following shows more examples:
REAL a (10)
LOGICAL, DIMENSION (5, 5) :: mask1, mask2
COMPLEX :: cube_root = (-0.5, 0.867)
INTEGER, PARAMETER :: short = SELECTED_INT_KIND (4)
REAL (KIND (0.0D0)) a1
REAL (KIND = 2) b
COMPLEX (KIND = KIND (0.0D0)) :: c
INTEGER (short) k ! Range at least -9999 to 9999
TYPE (member) :: george