switch break/fall (last minute request ... )
BCS
BCS at pathilink.com
Mon Dec 25 17:27:01 PST 2006
Hasan Aljudy wrote:
> 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;
> }
> -----------------
banning fall through but retaining "goto case;" and "goto case value;"
would have the same effect. But for some reason I like your suggestion
better. However, I'd rather just leave it all as it is.
What we need is a D-lint tool that would could enforce a set of
"Optional requirements". (Oh, cool name "D OptiOnal Requirements
System", DOORS!!!!).
More information about the Digitalmars-d
mailing list