Talk:Operator associativity

From Wikipedia, the free encyclopedia

[edit] Untrue statement

The following statement was removed by user 83.21.237.8 with the reason as "not true".

Associativity normally applies only to binary operators (operators with two arguments), written in infix notation, such as +, -, *, /.

What exactly are you disagreeing with?

  • If you disagree with the word binary, then perhaps you (or someone else) could add a section to the article on the associativity of operators with three arguments (like the ?: operator).
  • If you are disagreeing with the word infix, then know that associativity doesn't apply to polish notation (where all operators are prefix operators), or reverse polish notation (where all operators are postfix operators), because neither polish notation, or reverse polish notation is ambiguous.
  • Perhaps you were thinking that unary operators also have an associativity property. If you indeed have a definition for the associativity of a unary operators, perhaps you (or someone else) could add a section to the article to explain that and why it's useful. I would not consider it useful, because I don't think there is any ambiguity with unary operators that cannot be resolved by operator precedence. If you allow a unary operator to be used in both prefix and postfix notation, then yes, that could be ambiguous; e.g. the ++ operator in C: the expression ++x++ could be (++x)++ or ++(x++), but these are not ambiguous in practice because they both mean the same thing. Ambiguity introduced by the interaction between binary and unary operators (e.g. is -1+2 actually (-1)+2 or -(1+2)) is actually resolved by operator precedence and not associativity (unary minus has higher precedence than binary plus and minus).
  • If you are disagreeing with the narrow list of examples (+, -, *, /), then know that that was not intended to be a complete list.

--Egriffin (talk) 22:43, 28 March 2008 (UTC)