Previous Table of Contents Next


3.10.2 Semantics


   The <scoped_name> in the <const_type> production must be a previously defined name of an <integer_type>, <char_type>, <wide_char_type>, <boolean_type>, <floating_pt_type>, <string_type>, <wide_string_type>, <octet_type>, or <enum_type> constant.

   Integer literals have positive integer values. Only integer values can be assigned to integer type (short, long, long long) constants. Only positive integer values can be assigned to unsigned integer type constants. If the value of the right hand side of an integer constant declaration is too large to fit in the actual type of the constant on the left hand side, for example

   const short s = 655592;

   or is inappropriate for the actual type of the left hand side, for example

    const octet o = -54;

   it shall be flagged as a compile time error.

   Floating point literals have floating point values. Only floating point values can be assigned to floating point type (float, double, long double) constants. If the value of the right hand side is too large to fit in the actual type of the constant to which it is being assigned it shall be flagged as a compile time error.

   Fixed point literals have fixed point values. Only fixed point values can be assigned to fixed point type constants. If the fixed point value in the expression on the right hand side is too large to fit in the actual fixed point type of the constant on the left hand side, then it shall be flagged as a compile time error.

   An infix operator can combine two integers, floats or fixeds, but not mixtures of these. Infix operators are applicable only to integer, float and fixed types.

   If the type of an integer constant is long or unsigned long, then each subexpression of the associated constant expression is treated as an unsigned long by default, or a signed long for negated literals or negative integer constants. It is an error if any subexpression values exceed the precision of the assigned type (long or unsigned long), or if a final expression value (of type unsigned long) exceeds the precision of the target type (long).

   If the type of an integer constant is long long or unsigned long long, then each subexpression of the associated constant expression is treated as an unsigned long long by default, or a signed long long for negated literals or negative integer constants. It is an error if any subexpression values exceed the precision of the assigned type (long long or unsigned long long), or if a final expression value (of type unsigned long long) exceeds the precision of the target type (long long).

   If the type of a floating-point constant is double, then each subexpression of the associated constant expression is treated as a double. It is an error if any subexpression value exceeds the precision of double.

   If the type of a floating-point constant is long double, then each subexpression of the associated constant expression is treated as a long double. It is an error if any subexpression value exceeds the precision of long double.

   Fixed-point decimal constant expressions are evaluated as follows. A fixed-point literal has the apparent number of total and fractional digits. For example, 0123.450d is considered to be fixed<7,3> and 3000.00d is fixed<6,2>. Prefix operators do not affect the precision; a prefix + is optional, and does not change the result. The upper bounds on the number of digits and scale of the result of an infix expression, fixed<d1,s1> op fixed<d2,s2>, are shown in the following table:

Op Result: fixed<d,s>
+ fixed<max(d1-s1,d2-s2) + max(s1,s2) + 1, max(s1,s2)>
- fixed<max(d1-s1,d2-s2) + max(s1,s2) + 1, max(s1,s2)>
* fixed<d1+d2, s1+s2>
/ fixed<(d1-s1+s2) + sinf, sinf>

   A quotient may have an arbitrary number of decimal places, denoted by a scale of sinf. The computation proceeds pairwise, with the usual rules for left-to-right association, operator precedence, and parentheses. All intermediate computations shall be performed using double precision (i.e., 62 digit) arithmetic. If an individual computation between a pair of fixed-point literals actually generates more than 31 significant digits, then a 31-digit result is retained as follows:

   3-34 Common Object Request Broker Architecture (CORBA), v3.0 July 2002

   fixed<d,s> => fixed<31, 31-d+s>

   Leading and trailing zeros are not considered significant. The omitted digits are discarded; rounding is not performed. The result of the individual computation then proceeds as one literal operand of the next pair of fixed-point literals to be computed.

   Unary (+ -) and binary (* / + -) operators are applicable in floating-point and fixed-point expressions. Unary (+ -~) and binary (* / % + - << >> & | ^) operators are applicable in integer expressions.

   The “~? unary operator indicates that the bit-complement of the expression to which it is applied should be generated. For the purposes of such expressions, the values are 2’s complement numbers. As such, the complement can be generated as follows:

Integer Constant Expression Type

Generated 2’s Complement Numbers

long long -(value+1)
unsigned long unsigned long (2**32-1) - value
long long long long -(value+1)
unsigned long long unsigned long (2**64-1) - value

   The “%? binary operator yields the remainder from the division of the first expression by the second. If the second operand of “%? is 0, the result is undefined; otherwise

    (a/b)*b + a%b

   is equal to a. If both operands are nonnegative, then the remainder is nonnegative; if not, the sign of the remainder is implementation dependent.

   The “<<?binary operator indicates that the value of the left operand should be shifted left the number of bits specified by the right operand, with 0 fill for the vacated bits. The right operand must be in the range 0 <= right operand < 64.

   The “>>? binary operator indicates that the value of the left operand should be shifted right the number of bits specified by the right operand, with 0 fill for the vacated bits. The right operand must be in the range 0 <= right operand < 64.

   The “&? binary operator indicates that the logical, bitwise AND of the left and right operands should be generated.

   The “|? binary operator indicates that the logical, bitwise OR of the left and right operands should be generated.

   The “^? binary operator indicates that the logical, bitwise EXCLUSIVE-OR of the left and right operands should be generated.

   <positive_int_const> must evaluate to a positive integer constant.

   An octet constant can be defined using an integer literal or an integer constant expression, for example:

    const octet O1 = 0x1; const long L = 3;

    const octet O2 = 5 + L;

   Values for an octet constant outside the range 0 - 255 shall cause a compile-time error.

   An enum constant can only be defined using a scoped name for the enumerator. The scoped name is resolved using the normal scope resolution rules Section 3.20, “Names and Scoping,? on page 3-67. For example:

   enum Color { red, green, blue }; const Color FAVORITE_COLOR = red;

   module M {

   enum Size { small, medium, large };

   };

   const M::Size MYSIZE = M::medium;

   The constant name for the RHS of an enumerated constant definition must denote one of the enumerators defined for the enumerated type of the constant. For example:

   const Color col = red; // is OK but

   const Color another = M::medium; // is an error