Need help on operator associativity

Hi,
I would like to know which of the following expressions are valid and why:

a==b=c
a=b==c
a==b==c

I'm a bit confused with this associativity rules.

Assuming a, b, and c have built-in types

a==b=c
== has higher precedence than =, so this is parsed as (a==b) = c. The result of the built-in operator== is a bool rvalue, built-in operator= requires a modifiable lvalue, so this does not compile

a=b==c
== has higher precedence than =, so this is parsed as a=(b==c). The result of == is bool, this will compile if a has a type that can be assigned from bool (e.g. int)

a==b==c
== has left-to-right associativity, so this is compiled as (a==b)==c, the result of a==b is bool, and this compiles as long as c can be compared to bool (e..g if c is int)

That's very helpful, thanks a lot :D :D
Topic archived. No new replies allowed.