Is there ANY chance we can fix the bitwise operator precedence

bearophile bearophileHUGS at lycos.com
Sun Jun 20 16:42:49 PDT 2010


Sean Kelly:
> You mean every label that is followed by a statement, correct?  This is a common idiom that I wouldn't want to change:
> 
> switch (x) {
> case 1: case 2: case 3: case 4:
>     doSomething();
>     break;
> default:
>     whatever();
> }

I think he means every case. Sometimes a small change, even if seems a little less handy, is useful. Can't you write code like this, that also looks better to me?

import std.stdio: writeln;
void doSomething() { writeln("doSomething"); }
void whatever() { writeln("whatever"); }
void main() {
    int x = 4;
    switch (x) {
        case 1, 2, 3, 4:
            doSomething();
            break;
        default:
            whatever();
            break;
    }
}

Bye,
bearophile


More information about the Digitalmars-d mailing list