- 论坛徽章:
- 0
|
本帖最后由 幻の上帝 于 2012-01-12 13:08 编辑
1.预处理对constant-expression求值,并没有用到特殊的语法规则。和非预处理的constant-exprssion相同。
2.显式转换之前,后缀操作符之后。
3.有效,条件表达式可以是constant-expression。当然有点限制,需要保证能在预处理时求值。
依据:
ISO C11
6.6 Constant expressions
Syntax
1 constant-expression:
conditional-expression
Description
2 A constant expression can be evaluated during translation rather than runtime, and accordingly may be used in any place that a constant may be.
Constraints
3 Constant expressions shall not contain assignment, increment, decrement, function-call, or comma operators, except when they are contained within a subexpression that is not evaluated.115)
4 Each constant expression shall evaluate to a constant that is in the range of representable values for its type.
115) The operand of a sizeof operator is usually not evaluated (6.5.3.4).
Annex A.2.1
(6.5.2) postfix-expression:
primary-expression
postfix-expression [ expression ]
postfix-expression ( argument-expression-listopt )
postfix-expression . identifier
postfix-expression -> identifier
postfix-expression ++
postfix-expression --
( type-name ) { initializer-list }
( type-name ) { initializer-list , }
(6.5.2) argument-expression-list:
assignment-expression
argument-expression-list , assignment-expression
(6.5.3) unary-expression:
postfix-expression
++ unary-expression
-- unary-expression
unary-operator cast-expression
sizeof unary-expression
sizeof ( type-name )
alignof ( type-name )
(6.5.3) unary-operator: one of
& * + - ~ !
(6.5.4) cast-expression:
unary-expression
( type-name ) cast-expression
(6.5.15) conditional-expression:
logical-OR-expression
logical-OR-expression ? expression : conditional-expression
(6.6) constant-expression:
conditional-expression
(6.10)
if-group:
# if constant-expression new-line groupopt
# ifdef identifier new-line groupopt
# ifndef identifier new-line groupopt
elif-group:
# elif constant-expression new-line groupopt
|
|