A specification expression is an expression with limitations that you can use to specify items such as character lengths and array bounds.

A `specification expression` is a scalar, integer, restricted
expression.

A `restricted expression` is an expression in which each operation
is intrinsic and each primary is:

- A constant or a subobject of a constant.
- A variable that is a dummy argument that has neither the
**OPTIONAL**nor the**INTENT(OUT)**attribute, or a subobject of such a variable. - A variable that is in a common block, or a subobject of such a variable.
- A variable accessible by use association or host association, or a subobject of such a variable.
- An array constructor where each element and the bounds and strides
of each implied-
**DO**are expressions whose primaries are either restricted expressions or implied-**DO**variables. - A structure constructor where each component is a restricted expression.
- A reference to an array inquiry function (except
**ALLOCATED**), the bit inquiry function**BIT_SIZE**, the character inquiry function**LEN**, the kind inquiry function**KIND**, or a numeric inquiry function. Each argument is either a restricted expression, or it is a variable whose properties inquired about are not dependent on the upper bound of the last dimension of an assumed-size array, not defined by an expression that is not a restricted expression, or not definable by an**ALLOCATE**statement or by a pointer assignment statement.**+---------------------------------Fortran 95---------------------------------+**

- A reference to any remaining intrinsic functions defined in this
book where each argument is a restricted expression.
**+-----------------------------End of Fortran 95------------------------------+****+-------------------------------IBM Extension--------------------------------+**

- A reference to a system inquiry function, where any arguments are
restricted expressions.
**+----------------------------End of IBM Extension----------------------------+** - Any subscript or substring expression must be a restricted expression.
- A reference to a specification function, where any arguments are restricted expressions.

+---------------------------------Fortran 95---------------------------------+

You can use a `specification function` in a specification
expression. A function is a specification function if it is a pure function that
is not an intrinsic, internal or statement function. A specification
function cannot have a dummy procedure argument, and cannot be
recursive.

+-----------------------------End of Fortran 95------------------------------+

A variable in a specification expression must have its type and type parameters, if any, specified by a previous declaration in the same scoping unit, or by the implicit typing rules in effect for the scoping unit, or by host or use association. If a variable in a specification expression is typed by the implicit typing rules, its appearance in any subsequent type declaration statement must confirm the implied type and type parameters.

If a specification expression includes a reference to an inquiry function for a type parameter or an array bound of an entity specified in the same specification part, the type parameter or array bound must be specified in a prior specification of the specification part. If a specification expression includes a reference to the value of an element of an array specified in the same specification part, the array bounds must be specified in a prior declaration. The prior specification can be to the left of the inquiry function in the same statement.

LBOUND(C,2)+6 ! C is an assumed-shape dummy array ABS(I)*J ! I and J are scalar integer variables 276/NN(4) ! NN is accessible through host association

+---------------------------------Fortran 95---------------------------------+

The following example shows how a user-defined pure function,
`fact`, can be used in the specification expression of an
array-valued function result variable:

MODULE MOD CONTAINS INTEGER PURE FUNCTION FACT(N) INTEGER, INTENT(IN) :: N ... END FUNCTION FACT END MODULE MOD PROGRAM P PRINT *, PERMUTE('ABCD') CONTAINS FUNCTION PERMUTE(ARG) USE MOD CHARACTER(*), INTENT(IN) :: ARG ... CHARACTER(LEN(ARG)) :: PERMUTE(FACT(LEN(ARG))) ... END FUNCTION PERMUTE END PROGRAM P

+-----------------------------End of Fortran 95------------------------------+