Is there ANY chance we can fix the bitwise operator precedence rules?
bearophile
bearophileHUGS at lycos.com
Fri Jun 18 14:53:39 PDT 2010
Don:
> Tragic. Can we end this madness?
> Could we give & | ^ the same precedence as ==, making
> (a & mask == b) an error, just as (a < b == c) is rejected?
> That way we could lay this common bug to rest.
You can change the dmd compiler (even D1, if you want) applying this change and create a compiled "experiment version" that people can try (even people that don't compile dmd every day), to see possible side effects of this change, use it to spot bugs in their D code or inside Phobos, etc.
> BTW I think this a great cautionary tale about the dangers of rating
> backwards compatibility too highly.
Beside that one, there are few other parts of C/D code that I'd like still to turn into syntax errors in D2, like:
1) Implicit string concat (bug 3827, with an incomplete patch):
string[] a = ["foo", "bar" "baz"];
2) switch cases that don't end with goto or break:
void main() {
int x, y;
switch (x) {
case 0: y++;
default: y--;
}
}
3) Several usages of C comma operator.
And few others that I don't remember now.
----------------
Andrei Alexandrescu:
> A perhaps little known thing is that D doesn't allow this:
> int a, b, c;
> if (a < b < c) { ... }
> although it's compilable code in C.
It's a pity C compatibily forbids to use that syntax in D, because chained comparison operator syntax is handy in Python to tell if a value is in a range:
>>> 1 < 5 < 10
True
>>> "hello" < "zeta" < "red"
False
Bye,
bearophile
More information about the Digitalmars-d
mailing list