Compile-time expressions and optimizations

By default, the compiler evaluates expressions at compile time and performs other optimizations.

You can specify any expression that can be completely evaluated at compile time in a data declaration. This includes expressions whose operands are literals and intrinsic function calls that can be evaluated at compile time. The following functions are evaluated at compile time:

For example, the following is valid:

record
    fld   ,a(^size(prior_rec)+2)

As another example, on the following function:

%false

the compiler will evaluate %FALSE and emit a zero to the object file (instead of having the runtime evaluate %FALSE). On the function

%atrim("ab  ")

the compiler will emit the literal ab to the object file.

Optimizations

The compiler optimizes expressions as much as possible. At level 1, the compiler performs the following optimizations:

I1 + D2 - 22 + -2.4 + F2 + D1 + 25 - F1 - I2

(where I1 and I2 are integer variables, D1 and D2 are decimal variables, and F1 and F2 are implied-decimal variables) is evaluated as follows:

I1 - I2 + %integer(3) + D1 + D2 - F1 + F2 - 2.4