No more fall through in case statement?

Janice Caron caron800 at googlemail.com
Thu Jan 3 03:03:08 PST 2008


On 1/3/08, 0ffh <frank at youknow.what.todo.internetz> wrote:
> To me, a warning on nonempty case fallthrough seems more than enough...

I'm sure you know this already, but: "Warnings are not a defined part
of the D Programming Language."
(http://digitalmars.com/d/warnings.html)

Either it's an error, or it's not.

Hey - here's an idea. Why not make case statements have a syntax
similar to D's attributes. That is, if you use a colon, execution
continutes to end of scope (or break), but if you use curly braces,
only the stuff within the braces gets executed. (Just like "public",
"private", etc.)

For example:

    case 1:
        /*...*/
        /* falls through */
    case 2:
        /*...*/
       break;
    case 3
    {
        /*...*/
    }
        /* does not fall through */

Existing syntax will still work, so that C++ programmers won't get
confused. To get no-fall-through behaviour, you'd have to replace the
colon with an opening curly brace (and remember the closing brace).
Everyone's happy. (Maybe?)



More information about the Digitalmars-d mailing list