Is there ANY chance we can fix the bitwise operator precedence rules?

Jonathan M Davis jmdavisProg at gmail.com
Mon Jun 21 10:13:33 PDT 2010


KennyTM~ wrote:

> On Jun 19, 10 07:17, Jonathan M Davis wrote:
>> bearophile wrote:
>>
>>> 2) switch cases that don't end with goto or break:
>>>
>>> void main() {
>>>      int x, y;
>>>      switch (x) {
>>>          case 0: y++;
>>>          default: y--;
>>>      }
>>> }
>>
>> I, for one, _want_ case statements to be able to fall through. It would
>> be horribly painful in many cases if they couldn't. Now, requiring a
>> separate statement like fallthrough or somesuch instead of break might
>> not be a bad idea, but requiring that each case end with a break would
>> seriously restrict the usefulness of switch statements.
>>
>> - Jonathan M Davis
> 
> This "fallthrough" statement already exists.
> 
>      switch (x) {
>         case 0:
>           do_something();
>           goto case;
>         case 1:
>           do_more_thing();
>           goto case;
>         case 2:
>           done();
>           break;
>         default:
>           error();
>           break;
>      }

I forgot about that one. *Sigh* D has so many cool little features that 
sometimes it feels like I'm forgetting at least half of them. Oh well. It's 
silly to complain that D has too much cool stuff.

In any case, that means that it could be made required to have a control 
statement at the end of a case block without having to specify a specific 
destination for fallthrough - though I'd prefer "continue switch" over "goto 
case" since it's more explicit and less error prone (since there's no doubt 
that you didn't intend to put a destination for the goto if you use 
"continue switch" instead of a "goto case" without a destination). But we do 
have enough to make a control statement required without adding anything 
else to the language.

Thanks for pointing out that little detail of goto.

- Jonathan M Davis


More information about the Digitalmars-d mailing list