I can understand why the assignment operator is right associative. It makes sense that when
x = 4 + 3
is evaluated, that 4 and 3 are added before being assigned to x.
I am unclear as to how ?: would benefit from being right associative. Does it only matter when two ?:s were used like this
z = (a == b ? a : b ? c : d);
Then it is evaluated like this:
z = (a == b ? a : (b ? c : d));
Surely it would make more sense to evaluate from left to right?
If it evaluated from left to right, it’d look like this:
That is, it would use the result of the first conditional (
aorb) as the boolean condition of the second conditional. That doesn’t make much sense: that’s like saying:While perhaps one day you’ll want to do exactly this, it’s far more likely that each
?:that follows is meant to add more conditions, likeif/else if/else if/else, which is what the right-associative binding yields: