Array Constructor

Standard: F77 F90 F95 F2003 F2008 F2018 Example program


<Syntax>

(/ ac-spec /)
‘[’ ac-spec ‘]’

ac-spec ::= [ type-spec :: ] ac-val [ , ac-val ]...
| type-spec ::

ac-val ::= expression | ac-implied-do
ac-implied-do ::= ( ac-val [ , ac-val ]... , do-spec )

If no type-spec appears, the expressions must all have the same type and kind; furthermore, if they are of type character, they must all have the same length.

If a type-spec appears, the expressions must be assignment-compatible with the specified type and type parameters. Note that in the case of type character, this will pad or truncate the ac-val expressions to the length specified in the type-spec. If no ac-val appears, the constructor produces a zero-sized array.

<Semantics>

The array constructor creates an array value of rank one, with lower bound one. The type, kind (and length if character) of the value is specified by the type-spec if present, and otherwise is the same as that of the individual expressions . An expression may itself be an array, in which case it contributes the values of all of its elements in order.

If an array constructor contains an implied DO loop, the index variable is local to the array constructor: if the scoping unit has a local variable with the same name, evaluation of the array constructor (and thus execution of the implied DO) does not affect the value of that variable.

An array constructor that contains only constant expressions and implied DO loops is itself a constant, and can be used to define array parameters and initialise array variables.

In Fortran 2003, an array constructor can use square brackets [ ... ] instead of the parenthesis-slash combination (/ ... /). This makes expressions containing array constructors easier to read.

<Related>

Array Assignment, Array Section, DIMENSION attribute, DO statement, FORALL construct, FORALL statement, WHERE construct, WHERE statement