On 09/14/2011 09:11 PM, bearophile wrote:
simendsjo Wrote:

Not sure if this is a bug or as intended.

The semantics of switch is a mess (example: see 
http://d.puremagic.com/issues/show_bug.cgi?id=3820 ).
Mixing labels and switch cases seems a good way to create a bigger mess.

I think it is a bit mean to say the whole semantics is a mess, because there is an accepts-invalid bug. ;) What is really nice about D's case labels, is that they introduce a new scope. (as opposed to C) Unless they are mixed in: http://d.puremagic.com/issues/show_bug.cgi?id=6590 .

switch statements and gotos provide nice means of writing highly efficient code that still looks somewhat structured. I don't agree that using labels inside a switch creates a mess.


If I invert some things in your code I get an error...

import std.stdio;
void main() {
      int i = 1;
      switch(i) {
          case 0:
              writeln("case 0");
              goto default; // needed here
          aLabel:
              writeln("a label");
          default:
              writeln("default");
              // But always falls through here
      }
}

Bye,
bearophile

Well, yes, but that is as expected. Would you expect a fall through error on this code?

writeln(1);
label:
writeln(2);


labeled statements and case/default statements are not the same thing.

Reply via email to