- 论坛徽章:
- 1
|
原帖由 whyglinux 于 2005-10-31 21:11 发表
上面 trueno 说的是正确的,不知道为什么 flw 有不同意见啊?
C++ 的语法我没有看过权威资料,对标准不是很熟。
但是 C 的语法在我的记忆中一直都是对 && 和 || 的求值顺序没有规定。
今天又特意找到了一段资料,
可惜我的英文并不是很过关,因此发上来请兄台和我一起参祥参祥:
[#3] The grouping of operators and operands is indicated by |
the syntax.59) Except as specified later (for the function- |
call (), &&, ||, ?:, and comma operators), the order of
evaluation of subexpressions and the order in which side
effects take place are both unspecified.
.....
59)The syntax specifies the precedence of operators in the
evaluation of an expression, which is the same as the
order of the major subclauses of this subclause, highest
precedence first. Thus, for example, the expressions
allowed as the operands of the binary + operator (6.5.6) |
are those expressions defined in 6.5.1 through 6.5.6.
The exceptions are cast expressions (6.5.4) as operands
of unary operators (6.5.3), and an operand contained
between any of the following pairs of operators: grouping
parentheses () (6.5.1), subscripting brackets []
(6.5.2.1), function-call parentheses () (6.5.2.2), and
the conditional operator ?: (6.5.15).
Within each major subclause, the operators have the same
precedence. Left- or right-associativity is indicated in
each subclause by the syntax for the expressions
discussed therein.
原文出处:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n843.htm |
|