assignment: left-to-right or right-to-left evaluation?

Georg Wrede georg.wrede at iki.fi
Mon May 11 06:34:52 PDT 2009


Jason House wrote:
> Michel Fortin Wrote:
> 
>> On 2009-05-11 05:49:01 -0400, Georg Wrede <georg.wrede at iki.fi> said:
>>
>>> Andrei Alexandrescu wrote:
>>>> Consider:
>>>>
>>>> uint fun();
>>>> int gun();
>>>> ...
>>>> int[] a = new int[5];
>>>> a[fun] = gun;
>>>>
>>>> Which should be evaluated first, fun() or gun()?
>>> arra[i] = arrb[i++];
>>>
>>> arra[i++] = arrb[i];
>>>
>>> I'm not sure that such dependences are good code.
>>>
>>> By stating a definite order between lvalue and rvalue, you would 
>>> actually encourage this kind of code.
>>
>> Well, I agree with you that we shouldn't encourage this kind of code. 
>> But leaving it undefined (as in C) isn't a good idea because even if it 
>> discourages people from relying on it, it also makes any well tested 
>> code potentially buggy when switching compiler.
> 
> D2 could have no ordering guarantees, and simply give an error when
reordering could effect impure operations. Flow analysis could relax
this rule a bit. Local primitives that have not escaped are immune to
side effects affecting other variables.
> 
>> So even if you make it an error for the obvious cases, you still need 
>> to define the evaluation order for the ones the compiler can't catch.


C didn't define it for good reason. It should not be used, period.

Defining it in any way, or forbidding it, both mean that the compiler 
writer has to write lines of code to *try* to analyse it somehow. D is 
not a language for the infantile (even if I strongly advocate its use in 
language education), so we don't have to make this a bicycle with 
assist-wheels.

Walter's time is better spent on things that give more reward and take 
less of his time. And Andrei's, too.



More information about the Digitalmars-d mailing list