Developer Guide and Reference

ID 767251
Date 10/31/2024
Public
Document Table of Contents

Expressions

An expression represents either a data reference or a computation, and is formed from operators, operands, and parentheses. The result of an expression is either a scalar value or an array of scalar values.

If the value of an expression is of intrinsic type, it has a kind type parameter. (If the value is of intrinsic type CHARACTER, it also has a length parameter.) If the value of an expression is of derived type, it has no kind type parameter unless it is a parameterized derived type, in which case it may have kind and length type parameters..

An operand is a scalar or array. An operator can be either intrinsic or defined. An intrinsic operator is known to the compiler and is always available to any program unit. A defined operator is defined explicitly by a user in a function subprogram and is available to each program unit where it is accessible.

The simplest form of an expression (a primary) can be any of the following:

  • A constant; for example, 4.2

  • A subobject of a constant; for example, 'LMNOP' (2:4)

  • A variable; for example, VAR_1

  • A structure constructor; for example, EMPLOYEE(3472, "JOHN DOE")

  • An array constructor; for example, [12.0,16.0]

  • A function reference; for example, COS(X)

  • Another expression in parentheses; for example, (I+5)

  • A type parameter inquiry

  • A type parameter name

Any variable or function reference used as an operand in an expression must be defined at the time the reference is executed. If the operand is a pointer, it must be associated with a target object that is defined. An integer operand must be defined with an integer value rather than a statement label value. All of the characters in a character data object reference must be defined.

When a reference to an array or an array section is made, all of the selected elements must be defined. If a whole array is referenced, it cannot be assumed size. When a structure is referenced, all of the components must be defined. A reference to a function cannot be a reference to a function that returns a procedure pointer.

In an expression that has intrinsic operators with an array as an operand, the operation is performed on each element of the array. In expressions with more than one array operand, the arrays must be conformable (they must have the same shape). The operation is applied to corresponding elements of the arrays, and the result is an array of the same shape (the same rank and extents) as the operands.

In an expression that has intrinsic operators with a pointer as an operand, the operation is performed on the value of the target associated with the pointer.

For defined operators, operations on arrays and pointers are determined by the procedure defining the operation.

A scalar is conformable with any array. If one operand of an expression is an array and another operand is a scalar, it is as if the value of the scalar were replicated to form an array of the same shape as the array operand. The result is an array of the same shape as the array operand.