30 IDL, v4.2
According to those rules, a constant is defined by:
• The
const keyword.
• A type declaration, which shall denote a type suitable for a constant (
<const_type>), i.e.,:
• Either one of the following:
<integer_type>, <floating_pt_type>, <fixed_pt_const_type>, <char_type>,
<wide_char_type>, <boolean_type>, <octet_type>, <string_type>, <wide_string_type>, or a previously
defined enumeration . For a definition of those types, see 7.4.1.4.4, Data Types.
• Or a
<scoped_name>, which shall be a previously defined name of one of the above.
• The name given to the constant (
<identifier>).
• The operator
=.
• A value expression (
<const_expr>), which shall be consistent with the type declared for the constant.
For evaluating the value expression ( right hand side of the constant declaration) , the following rules shall be applied:
• If the type of an integer constant is
long or unsigned long, then each sub-expression 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 sub-expression 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 sub-expression 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 sub-expression 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 sub-expression of the associated constant expression
is treated as a
double. It is an error if any sub-expression value exceeds the precision of double.
• If the type of a floating-point constant is
long double, then each sub-expression of the associated constant
expression is treated as a
long double. It is an error if any sub-expression value exceeds the precision of long
double.
• An infix operator may combine two integer types, floating point types or fixed point types, but not mixtures of
these. Infix operators shall be applicable only to integer, floating point, and fixed point types.
• Integer expressions shall be evaluated based on the type of each argument of a binary operator in turn. If either
argument is
unsigned long long, it shall use unsigned long long. If either argument is long long, it shall use
long long. If either argument is unsigned long, it shall use unsigned long. Otherwise it shall use long. The
final result of an integer arithmetic expression shall fit in the range of the declared type of the constant;
otherwise it shall be treated as an error. In addition to the integer types, the final result of an integer arithmetic
expression may be assigned to an
octet constant, subject to it fitting in the range for octet type.
• Floating point expressions shall be evaluated based on the type of each argument of a binary operator in turn. If
either argument is
long double, it shall use long double. Otherwise it shall use double. The final result of a
floating point arithmetic expression shall fit in the range of the declared type of the constant; otherwise it shall
be treated as an error.
• Fixed-point decimal constant expressions shall be 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.