switch break/fall (last minute request ... )
Hasan Aljudy
hasan.aljudy at gmail.com
Mon Dec 25 17:04:30 PST 2006
Maybe it's pointless asking this now, five days before v1.0, but I'll
give it a try.
I would love it if there was a way to let the compiler catch the common
bug of forgetting a "break" statement after a case clause in a switch
statement.
The C behavior of automatically falling through is a cause of many many
bugs. It's really easy to forget a break and it's not really easy to
discover this bug.
I propose a new keyword, "fall", that would explicitly indicate the
coder's intention of allowing the switch statement to fall through to
the next case clause.
The absence of either "fall" or "break" would indicate an error.
Hypothetical example:
------------------
switch( X )
{
case A:
//something
fall; <-- falls through to the next case
case B:
//something
break; <-- break, same behavior as now
case C:
//something
case D: <-- error, no break or fall statement before case D
//something
break;
}
-----------------
More information about the Digitalmars-d
mailing list