In the C99 standard, expressions allow priority and associativity.
The priority is well-documented, since the order in which the operators appear in the document has a reduction in priority, so function calls come in front of multiplicative operators, which in turn come in front of additive operators.
However, I cannot find a definitive description of associativity, be it left or right. This is important because (35/5)*2 35/5*2 will be 14 for one option (35/5)*2 and 3 for another option 35/(5*2) .
Section 6.5 Expressions /3, footnote 74 state:
The syntax determines the priority of operators when evaluating an expression, which coincides with the order of the main subparagraphs of this subparagraph, with the highest priority.
In each main subquery, operators have the same priority. Left or right associativity is indicated in each subclause by the syntax of the expressions discussed in it.
However, taking a multiplicative case, for example:
6.5.5 Multiplicative Operators
Syntax
multiplicative-expression:
cast-expression
multiplicative-expression * cast-expression
multiplicative-expression / cast-expression
multiplicative-expression % cast-expression
Obstacles
Each of the operands must have an arithmetic type. The operands of the % operator must be of integer type. Semantics
Normal arithmetic conversions are performed on operands. The result of the binary operator * is the product of the operands.
The result of the operator / is the factor of dividing the first operand by the second; the result of the % operator is the remainder. In both operations, if the value of the second operand is zero, the behavior is undefined.
When integers are divisible, the result of the / operator is an algebraic relation with any fractional part being discarded. If the expression a/b is representable, the expression (a/b)*b + a%b will be equal to a .
I don't see anything where associativity is mentioned, and there seems to be no default setting elsewhere in the standard.
Did I miss something?
c iso associativity
paxdiablo
source share