Am Wed, 02 Apr 2014 00:04:42 +0200
schrieb Timon Gehr <timon.g...@gmx.ch>:

> On 04/01/2014 08:40 PM, Sarath Kodali wrote:
> > ...
> >
> > The evaluation order of assign operators should not be LTR as they
> > have right associativity. In "a = b = c", c has to be evaluated
> > first, then b and then a. Similarly, in "a = b + c", "b+c" has to
> > be evaluated first before a is evaluated. Otherwise it will be very
> > confusing, that in some cases it is LTR and in some it is RTL.
> 
> Note that this is after a paragraph that suggests to make evaluation
> in some cases LTR and in some RTL.
> 
> > Other binary operators like "+" have left associativity, and hence
> > evaluation for these should be LTR as mentioned in D spec.
> > ...
> 
> What's the presumed relation between associativity and evaluation
> order?
> 
> In particular, the ternary operator ?: is right associative. How on 
> earth are you going to evaluate it right to left?
> 
> > The C spec requires that the function arguments are to be pushed in
> > RTL order.
> 
> [citation needed]

The C standard explicitly doesn't define the evaluation order:
http://stackoverflow.com/questions/376278/parameter-evaluation-order-before-a-function-calling-in-c/376333#376333

It's probably the platform ABI for x86 which specifies this, however
this is architecture specific. For example ARM evaluates LTR.

> 
> > The DMD codegen uses pushl x86 instructions for pushing args. If the
> > frontend changes the func args evaluation order to LTR, then the
> > backend has to be modified  to use mov x86 instructions as is done
> > by gcc codegen.
> >
> > - Sarath
> >
> 
> The backend does not necessarily have to be modified to achieve this.

If this point is about performance it doesn't matter anyway as
parameters for extern(D) functions are already evaluated LTR and D
functions are much more common than C functions.

http://dpaste.dzfl.pl/f5a5caeea8ed

Reply via email to