HP Fortran Programmer's Reference (September 2007)

Expressions and assignment
Expressions
Chapter 492
The Standard allows the compiler to generate code that evaluates an expression by any
sequence that produces a result mathematically equivalent to the sequence implied by the
statement. This laxity permits code optimization, including (for example) the reordering of
expressions and the promotion of common subexpressions.
Because the order of evaluation is not defined by the Standard, a function reference within an
expression may not modify any of the other operands within the same expression. For
example, fun(x)+x is indeterminate if the reference to fun modifies the value of the
argument x.
Special forms of expression
Certain language constructs allow only restricted forms of expressions. For example, the
value specified for a named constant in a PARAMETER statement may be defined by an
expression, but it must be possible to evaluate the expression at compile-time. This means
that the expression must not contain any operands that depend on program execution for
their value. To take another example, a bound of a dummy array argument may be specified
as an expression, but it must be possible to evaluate this expression on entry to the
subprogram.
There are special restrictions imposed on operands and operators that may appear in an
expression, depending on whether the expression is one of the following:
Constant expressions
Initialization expressions
Specification expressions
The following sections describe the special forms of expression.
Constant expressions
A constant expression is either a constant or an expression containing only intrinsic
operators and constant operands. This restriction also applies to any clearly defined part of a
constant—for example, a substring with constant start and end points, or an array or
structure constructor. A constant expression may include references to intrinsic functions that
can be evaluated at compile-time. A constant expression may appear in any context in which
any expression may appear.
The following are examples of constant expressions:
123 ! an integer literal
”Hello ” // ” World” ! a character constant expression
3.0_single ! a real literal constant where single is