Specification expressions

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 type parameter of the derived type being defined.
  • 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 specification inquiry where each designator or function argument is either a restricted expression or a variable with properties that are not assumed, deferred, or defined by an expression that is not a restricted expression.
  • A reference to any remaining intrinsic functions defined in this document where each argument is a restricted expression.
  • IBM extension beginsA reference to a system inquiry function, where any arguments are restricted expressions. IBM extension ends
  • Any subscript or substring expression must be a restricted expression.
  • A reference to a specification function, where any arguments are restricted expressions.
A specification inquiry is a reference to:
  • An intrinsic inquiry function
  • A type parameter inquiry
  • An IEEE inquiry function

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.

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.

Examples

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


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us