@property needed or not needed?
Maxim Fomin
maxim at maxim-fomin.ru
Mon Jan 28 10:28:09 PST 2013
On Monday, 28 January 2013 at 17:41:07 UTC, Dicebot wrote:
> On Monday, 28 January 2013 at 17:20:13 UTC, Maxim Fomin wrote:
>> ...
>
> Those are C rules, do not forget it. Thus value of (b = c) IS
> equivalent to value of b when lvalues are considered. And you
> are perfectly allowed to forget about c and do a = b after b =
> c was evaluated. It is plain old data, after all, if b = c is
> not interchangeable with b, something is wrong.
>
> At least I see nothing in standard that proves your statement.
>
You are still breaking expression a = b = c and mixing terms of
value of expression and expression itself.
>>
>> Applying your logic:
>>
>> Left operand for a = (b = c) is a. Thus a has value of (b =
>> c). Value of b = c is b.setter(c.getter()).
>
> You are applying it wrong. Thing of it as of recursion.
I applied exactly as you did.
> 1) evaluate "a = b = c"
> 2) evaluate a.set( (b = c).get() ), result of 1 will be a.get()
> ( if needed )
.get() is wrong here. Expression is a = b = c, not a = ( (b =
c).get ))
> 3) evaluate "b = c"
> 4) evaluate b.set( c.get() ), result of 3 will be b.get() ( if
> needed )
> 5) combine: a.set( b.set( c.get() ), b.get() )
This breaks requirement from quoted paragraph that side effects
are sequenced after value computations on both operands:
computing value of b (b.get) happened after updating value
(b.set).
In Bugzilla there were close to this case like following (do not
remember #):
struct S { int a; int b; int c; }
...
S s1, s2;
s1 = { 1, s1.a 2 }
Compiler was wrongly applied side effects before evaluating s1.a
(it should be zero, not 1).
> Note that evaluation order for comma expression is defined, so
> "c.get() ), b.get()" is valid and correct code.
Well, discussion went repetitive - I still insists that a = b = c
should be evaluated as it is currently a.set(b=c) = >
a.set(b.set(c)) => a.set(b.set(c.get)). By the way, this C#
program also behaves as I understand rules:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class S
{
int _i;
public int i
{
get { Console.WriteLine("getter"); return _i; }
set { Console.WriteLine("setter"); _i = value; }
}
}
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
S s1 = new S() , s2 = new S(), s3 = new S();
s1.i = s2.i = s3.i;
}
}
}
getter
setter
setter
More information about the Digitalmars-d
mailing list