Why does D change operator precedence according to C/C++ ?
Simen Kjaeraas
simen.kjaras at gmail.com
Mon Apr 2 03:32:01 PDT 2012
On Mon, 02 Apr 2012 12:03:14 +0200, deadalnix <deadalnix at gmail.com> wrote:
> Hi,
>
> I have a design question, or maybe it is a bug ? In D, == and != have
> the same precedence than comparisons operators. This isn't the case in
> C/C++ . Is it a design decision, made on purpose ? Is it a bug ?
>
> DMD implementation and http://dlang.org/expression.html both agree on
> that.
>
> I personally think it is a bug. This is a change in the behavior of
> C/C++ with no legitimate reason. Or at least with no legitimate reason I
> can come up with.
It's there to force proper parenthezation:
1 <= 3 == 2 > 3 != 3 < 1
vs
((1 <= 3) == (2 > 3)) != (3 < 1)
vs
(1 <= (3 == 2)) > ((3 != 3) < 1)
More information about the Digitalmars-d
mailing list