CHARACTER Statement

Description

The CHARACTER statement declares entities having the CHARACTER data type.

Syntax

CHARACTER [char-selector] [, attribute-list ::] entity [,
entity] ...

Where:

char-selector is:

([LEN=] length [, KIND=kind])

or (KIND=kind [, LEN=length])

or * char-length [,]

kind is a scalar INTEGER expression that can be evaluated at compile time.

length is a scalar INTEGER expression that can be evaluated on entry to
the program unit, or *

char-length is a scalar INTEGER literal constant, or (*)

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)] [* char-length] [=initialization-expr]

or function-name [(array-spec)] [* char-length]

array-spec is an array specification

initialization-expr is a CHARACTER-valued expression that can be evaluated
at compile time

entity-name is the name of the entity being declared

function-name is the name of a function being declared

Remarks

If char-length is not specified, the length is one.

An asterisk can be used for char-length only in the following ways:

If the entity is a dummy argument. The dummy argument assumes the length of the
associated actual argument.

To declare a named constant. The length is that of the constant value.

In an external function, as the length of the function result. In this case, the
function name must be declared in the calling scoping unit with a length other than
*, or access such a definition by host or use association. The length of the result
variable is assumed from this definition.

char-length for CHARACTER-valued statement functions and statement function
dummy arguments must be a constant INTEGER expression.

The optional comma following * char-length in a char-selector
is permitted only if no double colon appears in the statement.

The value of kind must specify a character set that is valid for this compiler.

char-length must not include a kind parameter.

The *char-length in entity specifies the length of a single entity and
overrides the length specified in char-selector.

function-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.

If char-length is a non-constant expression, the length is declared at
the entry of the procedure and is not affected by any redefinition of the variables
in the specification expression during execution of the procedure.