Topic: Why it is impossible to write x + = 2 + = 3?

It is known that assignment use right-association rule, i.e. it x + = y + = z is compiled as x + = (y + = z) And why actually not as (x + = y) + = z? I.e. with the left association. If there would be a "left" variant that it would be possible for example in JS to write var vec = []; vec + = 1 + = 2; i.e. chained push ()... In what  the right association?

Re: Why it is impossible to write x + = 2 + = 3?

Hello, c-smile, you wrote: CS> In what  the right association? All is very simple. The operator + = concerns group of assignment statements, at which at all one associativity. I hope, associativity of the simple operator = does not cause questions in you? You after all for certain would not like, that the code x = y = z = 0; it was compiled as ((x = y) = z) = 0;?

Re: Why it is impossible to write x + = 2 + = 3?

Hello, jazzer, you wrote: J> Hello, c-smile, you wrote: CS>> In what  the right association? J> all is very simple. The operator + = concerns group of assignment statements, at which at all one associativity. J> I Hope, associativity of the simple operator = does not cause questions in you? J> you after all for certain would not like, that the code x = y = z = 0; it was compiled as ((x = y) = z) = 0;? Assignment is separate operation. An increment it is basic other operation. Is not present? Or there worked trivial similarity: type there is an equal sign - the right associativity...

Re: Why it is impossible to write x + = 2 + = 3?

Hello, c-smile, you wrote: CS> Assignment is separate operation. An increment it is basic other operation. Is not present? Nevertheless, in With ++ all of them in a crowd are called assignment-expression and differences any does not become. All is: =, + =, - =, * =, / =, % =, &=, | =, ^ =, <<=,>> = CS> Or there worked trivial similarity: type there is an equal sign - the right associativity... Associativity is registered in grammar (Appendix A in the standard, look if it at you is near at hand), therefore for all assignment-expression it identical. Otherwise it should to enter into grammar in addition one more class of assignment specially for simple assignment with other associativity.

Re: Why it is impossible to write x + = 2 + = 3?

Hello, c-smile, you wrote: CS> It is known that assignment use right-association rule, i.e. it CS> CS> x + = y + = z CS> CS> is compiled as CS> CS> x + = (y + = z) CS> CS> And why actually not as CS> CS> (x + = y) + = z CS> CS>? I.e. with the left association. CS> if there would be a "left" variant that it would be possible for example in JS to write CS> CS> var vec = []; CS> vec + = 1 + = 2; CS> CS> i.e. chained push ()... CS> In what  the right association? Try to use the operator "= +".

Re: Why it is impossible to write x + = 2 + = 3?

Hello, c-smile, you wrote: CS> And why actually not as CS> CS> (x + = y) + = z CS> CS>? I.e. with the left association. And to whom in this construction value z will be appropriated? Hint: result of performance of expression (x + = y) is value x after assignment, instead of the link on x.

Re: Why it is impossible to write x + = 2 + = 3?

Hello, jazzer, you wrote: J> Hello, c-smile, you wrote: CS>> Assignment is separate operation. An increment it is basic other operation. Is not present? J> Nevertheless, in With ++ all of them in a crowd are called assignment-expression and differences any does not become. J> all is: =, + =, - =, * =, / =, % =, &=, | =, ^ =, <<=,>> = That that in a name is assignment means nothing. By the way correctly they should be called inplace mutators that-whether... To assignment they strictly speaking do not concern. For example x + = 1 it ++ x that is increment (but not x ++, anyway in a canonical form) CS>> Or there worked trivial similarity: type there is an equal sign - the right associativity... J> associativity is registered in grammar (Appendix A in the standard, look if it at you is near at hand), therefore for all assignment-expression it identical. J> Differently it should to enter into grammar in addition one more class of assignment specially for simple assignment with other associativity. It here x + y + z; it is executed as (x + y) + z; whereas x + = y + = z; x + = (y + = z);  quits. Well and figs with it

Re: Why it is impossible to write x + = 2 + = 3?

Hello, c-smile, you wrote: CS> Hello, jazzer, you wrote: J>> Hello, c-smile, you wrote: CS>>> Assignment is separate operation. An increment it is basic other operation. Is not present? J>> Nevertheless, in With ++ all of them in a crowd are called assignment-expression and differences any does not become. J>> all is: =, + =, - =, * =, / =, % =, &=, | =, ^ =, <<=,>> = CS> That that in a name is assignment means nothing. By the way correctly they should be called inplace mutators that-whether... CS> To assignment they strictly speaking do not concern. I not so understand, with what you argue. Here the first paragraph from C: 5.17 Assignment operators [expr.ass] 1 There are several assignment operators, all of which group right-to-left. All require a modifiable lvalue as their left operand, and the type of an assignment expression is that of its left operand. The result of the assignment operation is the value stored in the left operand after the assignment has taken place; the result is an lvalue. assignment-expression: conditional-expression logical-or-expression assignment-operator assignment-expression throw-expression assignment-operator: one of = * = / = % = + = - =>> = <<= &= ^ = | =

Re: Why it is impossible to write x + = 2 + = 3?

Hello, c-smile, you wrote: CS> It is known that assignment use right-association rule, i.e. it CS> CS> x + = y + = z CS> CS> is compiled as CS> CS> x + = (y + = z) CS> CS> And why actually not as CS> CS> (x + = y) + = z CS> CS>? I.e. with the left association. CS> if there would be a "left" variant that it would be possible for example in JS to write CS> CS> var vec = []; CS> vec + = 1 + = 2; CS> CS> i.e. chained push ()... CS> In what  the right association? We consider any infernal example. e = a + b + = c + d what behavior we will expect here? It, on idea, the same, as e = a + b = b + c + d that is should be displaced here so: e = (a + (b = (b + c + d)) Or e = a + (b + = (c + d) that is,  the right associativity is necessary.