No more fall through in case statement?

S. S at s.com
Mon Jan 7 15:02:28 PST 2008


bearophile Wrote:

> S. Wrote:
> > I, at various times, have written code that depends on case statements falling through, while not being identical!
> 
> If you take a look at my original post, I have suggested to use a "fall" or "continue" statement when you want to go down, and nothing if you want the default of going at the end of the switch...
> 
> Bye,
> bearophile

The same problems you initially mentioned still exist in your proposal.  You just moved them around:

caseof(Foo)
{
  case 'foo':
     writeflin("bar");
     fall;
     x = 3;
  case 'bar':
    writefln("OMGWTF X != 3");
}

Whatever complicated syntax you invent there will be unreachable code.  The compiler should produce ERRORS on any unreachable code.

The error you linked to is not switch-induced, but stupidity induced.  However, I will say this:  D is starting to become so complex that it is becoming difficult to understand the entire specification.   Once it is no longer feasible to have the spec memorized then it becomes easy to make very silly mistakes.

-S.



More information about the Digitalmars-d mailing list