Is there ANY chance we can fix the bitwise operator precedence

Sean Kelly sean at invisibleduck.org
Sun Jun 20 17:59:17 PDT 2010


bearophile Wrote:

> 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;
>     }
> }

As long as there's a way to enumerate case labels I don't really care what the syntax is.  That would be more than fine with me.


More information about the Digitalmars-d mailing list