Intrinsic Assignment Statements

Intrinsic assignment is used to assign a value to a nonpointer variable. In the case of pointers, intrinsic assignment is used to assign a value to the target associated with the pointer variable. The value assigned to the variable (or target) is determined by evaluation of the expression to the right of the equal sign.

An intrinsic assignment statement takes the following form:

variable = expression

variable

Is the name of a scalar or array of intrinsic or derived type (with no defined assignment). The array cannot be an assumed-size array, and neither the scalar nor the array can be declared with the PARAMETER or INTENT(IN) attribute. If it has the OPTIONAL attribute, it must be PRESENT if the assignment statement is executed.

expression

Is of a compatible intrinsic type if variable is of intrinsic type or of the same derived type as variable, if variable is not polymorphic; otherwise, it must be of a type that is type compatible with variable. Its shape must conform with variable.

Unless the variable is unlimited polymorphic, an intrinsic typed expression is converted to the same type and kind as variable when possible.

Description

Before a value is assigned to variable, expression and any expressions within variable are evaluated. No definition of expressions in variable can affect or be affected by the evaluation of expression.

variable must be allocatable if it is polymorphic. The value of expression is assigned to the target of variable if variable is a pointer.

If variable is an allocatable array, expression must have the same rank. If variable is an allocated allocatable variable, it is deallocated under these conditions:

If variable is unallocated, or becomes unallocated during the assignment statement, it becomes allocated with the following:

Note

When the runtime system assigns a value to a scalar integer or character variable and the variable is shorter than the value being assigned, the assigned value may be truncated and significant bits (or characters) lost. This truncation can occur without warning, and can cause the runtime system to pass incorrect information back to the program.

The following rules apply to intrinsic assignment statements:

If variable is of enum type type-name, and expression is of integer type, the behavior is as if the statement was written as:

variable = type-name (expression)

where type-name (expression) is an enum constructor.

See Also