04-09-2008, 12:07 PM
ISO C is wonderfully fuzzy when it comes to precedence rules...
That first link would be a copy of ISO C 9899:1999 chapter 6.5 "Expressions". The whole definition of the extremely important operator precedence rules in ISO C are found in a tiny subclause...
6.5 row 3:
"The grouping of operators and operands is indicated by the syntax.71) 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."
Tiny subclause in fine print:
"71) 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."
And there you have it, the very definition of the precedence rules every C programmer is expected to know. There is no other documentation in the standard over this.
In plain English, the operator precedence in ISO C is defined by the order the description of the operands are written in the document. You just need to check in what order they appear in that lovely section of 30 pages...
That first link would be a copy of ISO C 9899:1999 chapter 6.5 "Expressions". The whole definition of the extremely important operator precedence rules in ISO C are found in a tiny subclause...
6.5 row 3:
"The grouping of operators and operands is indicated by the syntax.71) 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."
Tiny subclause in fine print:
"71) 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."
And there you have it, the very definition of the precedence rules every C programmer is expected to know. There is no other documentation in the standard over this.
In plain English, the operator precedence in ISO C is defined by the order the description of the operands are written in the document. You just need to check in what order they appear in that lovely section of 30 pages...
<t></t>