"James Kanze" <> wrote in message
news: oups.com...
On Oct 4, 10:29 pm, red floyd <no.s...@here.dude> wrote:
> There is no real operator precedence. Consider:
> a = b ? c : d, e ; // precedence: ?:, =, ,
> a ? b = c, d : e ; // precedence: =, ,, ?:
Although it may not be obvious, it is possible to apply precedence rules
even in the case of ?:.
Here are the rules:
1) Replace every ? with ?( and every : with ):
2) It is now possible to speak unambiguously about the precedence of ?:
3) The precedence rule may be somewhat surprising:
?: has the same precedence as the assignment operators,
and, like the assignment operators, is right-associative.
These rules handle your examples as follows:
a = b ? c : d , e becomes a = b ?( c ): d , e because of rule (1) above
?: has higher precedence than , so this example is equivalent to
(a = b ?( c ): d), e
a ? b = c, d : e becomes a ?(b = c, d ): e because of rule (1) above
= has higher precedence than , so this example is equivalent to
a ?((b = c), d): e
|