@property needed or not needed?
Maxim Fomin
maxim at maxim-fomin.ru
Mon Jan 28 08:50:36 PST 2013
On Monday, 28 January 2013 at 15:31:48 UTC, Dicebot wrote:
> On Monday, 28 January 2013 at 15:05:21 UTC, Maxim Fomin wrote:
>> It should be rewritten to a.setter(b.setter(c.getter()))
> That is exactly the problem. "a = b = c" should be rewritten as:
> b.set(c.get());
> a.set(b.get()); // or a.set(c.get()); do not remember C rules
From ISO C Assignment operators chapter: "An assignment operator
stores a value in the object designated by the left operand. An
assignment expression has the value of the left operand after the
assignment,111) but is not an lvalue. The type of an assignment
expression is the type the left operand would have after lvalue
conversion. The side effect of updating the stored value of the
left operand is sequenced after the value computations of the
left and right operands. The evaluations of the operands are
unsequenced.".
So, in right-associative expression a = b = c, at first
subexpression b = c is evaluated to b.set(c.get). Than value of
this expression (note, that evaluated expression is not b, it is
b = c) is assigned to a. How it can be done if b.set() returns
void? Than expression a = (b = c) is evaluated to a.set( b = c)
which is (a.setter(b.setter(c.getter))
b.setter cannot be called prior to b.getter as in your example #1
due to sequence rules. The example #2 would be for expression a =
c, b = c which is not a = b = c in the presence of properties.
More information about the Digitalmars-d
mailing list