NoNo for Associativity of Assignments?

Manfred Nowak svv1999 at hotmail.com
Thu Feb 22 23:13:34 PST 2007


Now that the associativity of comparisons has been dropped, I have
the heart to point the readers attention to the associativity of
assignments: 

  There is no evaluation order specified for assignments.

>From the specs:
| The right operand is implicitly converted to the type of the left
| operand, and assigned to it. The result type is the type of the
| lvalue, and the result value is the value of the lvalue after the
| assignment. 
| The left operand must be an lvalue. 

and

| It is an error to depend on order of evaluation when it is not
| specified. 


This means: "a = b = c;" is an error unless "a == b" and "b == c"!

But if both conditions hold "a = b = c;" is illegal:

| Expressions that have no effect, like (x + x), are illegal in
| expression statements.

Canonical solutions for this dilemma:
- drop associativity
- specify evaluation order

-manfred
 





More information about the Digitalmars-d mailing list