Operator Priority and Associativity in C / C ++

Note that this has nothing to do with Operator Priority .. () and ++ , Undefined behavior and sequence points , Why are these constructs (using ++) undefined behavior? and hundreds of similar questions about it here south>


In the near future : is there associativity guaranteed by the standard?

Detailed example : from Wikipedia, the article for operator priority, operator* and operator/ have the same priority, and they are Left-to-right operators. Does this mean that the standard guarantees that it:

 int res = x / y * z / t; 

will be rated as

 int res = ( ( x / y ) * z ) / t; 

or implementation defined?

If this were guaranteed, could you quote?


It’s just out of curiosity, I always write brackets in these cases.
Ready to delete the question, if there is one.

+4
source share
2 answers

From the last public project

5.6 Multiplicative operators [expr.mul]

1 Multiplicative operators *, / and% of the group from left to right.

 multiplicative-expression: pm-expression multiplicative-expression * pm-expression multiplicative-expression / pm-expression multiplicative-expression % pm-expression 

So, the parsing will look like this:

 int res = x / y * z / t; int res = (x / y * z) / t; int res = ((x / y) * z) / t; 
+6
source

n3337 5.6 / 1

Multiplicative operators *, / and% of the group from left to right.

Read 5 standard pairs.

+5
source

All Articles