Constant Expressions
Next: Primaries
Up: Expressions
Previous: Precedence and Associativity
Constant expressions are a limited kind of expression that can be used
in equates. They are evaluated at compile time to produce objects of
built-in, immutable types. They can contain method calls but only to
methods belonging to compile-time known, built-in immutable objects;
the only other calls are to certain built-in, side-effect-free
routines. The following forms are allowed:
- literals (7.1)
- constructors for "struct"s, "oneof"s,
and "maybe"'s, provided all fields are assigned constant expressions
(7.3);
- calls of the built-in routines that create new
sequences (B.9), provided all the arguments are constant
expressions.
- equated identifiers (4.6);
- identifiers that name built-in or user-defined stand-alone
routines;
- instantiations of built-in or user-defined parameterized,
stand-alone routines;
- selection of methods of objects denoted by constant expressions;
- invocation
of methods of objects denoted by
constant expressions provided the actual arguments are also
constant expressions.
Evaluation of a constant expression must terminate normally
or there will be a compile-time error.
theta-questions@lcs.mit.edu