- 论坛徽章:
- 0
|
回复 #6 ynchnluiti 的帖子
ok,结帖吧
A constant expression can be used any place a constant can be used. The syntax
is as follows:
constant-expression: conditional-expression
A constant expression cannot contain assignment, increment, decrement,
function-call, or comma operators. It must evaluate to a constant that is in the
range of representable values for its type. Otherwise, the semantic rules for the
evaluation of nonconstant expressions apply.
Constant expressions are separated into three classes:
• An integral constant expression has integral type and is restricted to
operands that are integral constants, sizeof expressions (whose operands
do not have variable length array type or a parenthesized name of such a
type), and floating constants that are the immediate operands of integral
casts.
• An arithmetic constant expression has arithmetic type and is restricted to
operands that are arithmetic constants, and sizeof expressions (whose
operands do not have variable length array type or a parenthesized name of
such a type). Cast expressions in arithmetic constant expressions can convert
only between arithmetic types.
• An address constant is a pointer to an lvalue designating an object of static
storage duration, or a pointer to a function designator. It can be created
explicitly or implicitly, as long as no attempt is made to access an object
value.
Either address or arithmetic constant expressions can be used in initializers. In
addition, initializers can contain null pointer constants and address constants
(for object types), and plus or minus integral constant expressions. |
|