02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Expressions and assignment<br />

Expressions<br />

The Standard allows the compiler to generate code that evaluates an expression by any<br />

sequence that produces a result mathematically equivalent to the sequence implied by the<br />

statement. This laxity permits code optimization, including (for example) the reordering of<br />

expressions and the promotion of common subexpressions.<br />

Because the order of evaluation is not defined by the Standard, a function reference within an<br />

expression may not modify any of the other operands within the same expression. For<br />

example, fun(x)+x is indeterminate if the reference to fun modifies the value of the<br />

argument x.<br />

Special forms of expression<br />

Certain language constructs allow only restricted forms of expressions. For example, the<br />

value specified for a named constant in a PARAMETER statement may be defined by an<br />

expression, but it must be possible to evaluate the expression at compile-time. This means<br />

that the expression must not contain any operands that depend on program execution for<br />

their value. To take another example, a bound of a dummy array argument may be specified<br />

as an expression, but it must be possible to evaluate this expression on entry to the<br />

subprogram.<br />

There are special restrictions imposed on operands and operators that may appear in an<br />

expression, depending on whether the expression is one of the following:<br />

90<br />

Constant expressions<br />

Initialization expressions<br />

Specification expressions<br />

The following sections describe the special forms of expression.<br />

Constant expressions<br />

A constant expression is either a constant or an expression containing only intrinsic<br />

operators and constant operands. This restriction also applies to any clearly defined part of a<br />

constant—for example, a substring with constant start and end points, or an array or<br />

structure constructor. A constant expression may include references to intrinsic functions that<br />

can be evaluated at compile-time. A constant expression may appear in any context in which<br />

anyexpressionmayappear.<br />

The following are examples of constant expressions:<br />

123 ! an integer literal<br />

”Hello ” // ” World” ! a character constant expression<br />

3.0_single ! a real literal constant where single is<br />

Chapter 5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!