[D1][expressions] Order Of Evaluation
Denis Koroskin
2korden at gmail.com
Fri Oct 8 09:43:19 PDT 2010
On Fri, 08 Oct 2010 18:49:36 +0400, %u <e at ee.com> wrote:
> /The following binary expressions are evaluated in an
> implementation-defined
> order:
> AssignExpression/../AddExpression/
>
> /It is an error to depend on order of evaluation when it is not
> specified./
>
> That makes this an error!?
>
> y = x + 1;
>
> Am I being paranoid or should I be adding more brackets?
Assignment has higher precedence that addition so your code has no errors.
However, the following one does:
int x = 1;
int y = (x = 2) + x;
because "x" and "x = 2" has same precedence and thus may be evaluated in
any order.
Stay away from such code and you should be fine.
More information about the Digitalmars-d-learn
mailing list