COMPLEX
Purpose
A COMPLEX type declaration statement specifies the length and attributes of objects and functions of type complex. Initial values can be assigned to objects.
Syntax
where:
- attr_spec
- is any of the following:
- kind_selector
- specifies the length of complex entities:
- If int_constant_expr is specified, the valid values are 4, 8 and 16. These values represent the precision and range of each part of the complex entity.
- If the *int_literal_constant form is specified, the valid values are 8, 16 and 32. These values represent the length of the whole complex entity, and correspond to the values allowed for the alternative form. int_literal_constant cannot specify a kind type parameter.
- attr_spec
- For detailed information on rules about a particular attribute, refer to the statement of the same name.
- intent_spec
- is either IN, OUT, or INOUT
- ::
- is the double colon separator. Use the double colon separator when you specify attributes, =constant_expr, or => NULL().
- array_spec
- is a list of dimension bounds.
- entity_decl
-

>>-a--+-+--------------+--+------------------+-+---------------->
| | (1) | '-(--array_spec--)-' |
| '- * --len-----' |
| (2) |
'-(--array_spec--)-- * --len-------------'
>--+----------------------------------+------------------------><
| (3) |
'-+-/--initial_value_list--/-----+-'
+- = --constant_expr-----------+
'- => --NULL()-----------------'
Notes:- IBM extension.
- IBM extension.
- IBM extension.
-
- a
- is an object name or function name. array_spec cannot be specified for a function with an implicit interface.
len- overrides the length as specified in kind_selector,
and cannot specify a kind type parameter. The entity length must be
an integer literal constant that represents one of the permissible
length specifications.

initial_value- provides an initial value for the entity specified by the immediately
preceding name.

- constant_expr
- provides a constant expression for the entity specified by the immediately preceding name.
- => NULL()
- provides an initial value for the pointer object
Rules
- If => appears in a component initialization, the POINTER attribute must appear in the attr_spec_list.
- If = appears in a component initialization, the POINTER attribute cannot appear in the component attr_spec_list.
- The compiler will evaluate constant_expr within the scoping unit of the type definition.
If => appears for a variable, the object must have the POINTER attribute.
If constant_expr appears for a variable, the object cannot have the POINTER attribute.
Entities in type declaration statements are constrained by the rules of any attributes specified for the entities, as detailed in the corresponding attribute statements.
The type declaration statement overrides the implicit type rules in effect. You can use a type declaration statement that confirms the type of an intrinsic function. The appearance of a generic or specific intrinsic function name in a type declaration statement does not cause the name to lose its intrinsic property.
- it appears in a named common block in a block data program unit.
if it appears in a named common block in a module or submodule.
In Fortran 95, a pointer can be initialized. Pointers can only be initialized by the use of => NULL().
The specification expression of an array_spec can be a nonconstant expression if the specification expression appears in an interface body or in the specification part of a subprogram. Any object being declared that uses this nonconstant expression and is not a dummy argument or a pointee is called an automatic object.
An attribute cannot be repeated in a given type declaration statement, nor can an entity be explicitly given the same attribute more than once in a scoping unit.
- is a variable, the variable is initially defined.
- is a derived type component, the derived type has default initialization.
a becomes defined with the value determined by constant_expr, in accordance with the rules for intrinsic assignment. If the entity is an array, its shape must be specified either in the type declaration statement or in a previous specification statement in the same scoping unit.
A variable or variable subobject cannot be initialized more than once. If a is a variable, the presence of constant_expr or NULL() implies that a is a saved object, except for an object in a named common block. The initialization of an object could affect the fundamental storage class of an object.
An array_spec specified in the entity_decl takes precedence over the array_spec in the DIMENSION attribute.
An array
function result that does not have the
ALLOCATABLE or
POINTER attribute
must have an explicit-shape array specification.
If the entity declared is a function, it must not have an accessible explicit interface unless it is an intrinsic function.
If T or F, defined previously
as the name of a constant, appears in a type declaration statement,
it is no longer an abbreviated logical constant but the name of the
named constant.
Examples
COMPLEX, DIMENSION (2,3) :: ABC(3) ! ABC has 3 (not 6) array elements
Related information
- Complex
- Constant expressions
- Determining Type, for details on the implicit typing rules
- Array declarators
- Automatic objects
- Storage classes for variables (IBM extension)
- DATA, for details on initial values


