grauzone wrote:
BCS wrote:
Hello grauzone,

http://groups.google.com/group/net.lang.c/msg/66008138e07aa94c

Many people (even Brian Kernighan?) have said that the worst feature
of C is that switches don't break automatically before each case
label.

Oh god, that's from 1984, and even today we're struggling with this
bullshit in the most modern dialect of C, D.


I'm sorry, you don't have my sympathy on this one. There are to many place I've used fall throught to chuck it out.

What kind of fall-throughs were these?

A:

case value1:
case value2:
case valueN:
    code1();
    break;

B:

case value1:
    code1();
case value2:
    code2();
    break;

The solution is to forbid fallthrough, and change the switch syntax:

switch(value) {
  case 1:
  case 2:
        // something
        break;
}

gives: Error, missing break at the end of case1.

But:

switch(value) {
  case 1, 2:
        // something
        break;
}

works as expected.

What's wrong with that?

Reply via email to