No more fall through in case statement?
Bill Baxter
dnewsgroup at billbaxter.com
Thu Jan 3 16:30:25 PST 2008
S. wrote:
> This whole conversation about switch was kind of lost on me,
Don't worry, none of it will ever happen in D, anyway.
> but I have to contribute this.
> I, at various times, have written code that depends on case statements falling through, while not being identical!
>
> For example:
>
> switch(foo)
> {
> case 'bob':
> //Do bob stuff
> //Fall through and doo bar stuff too.
> case 'bar':
> //Do bar stuff and exit
> break;
>
> case 'baz':
> //Do some baz stuff
> break;
> }
>
> Whatever is changed shouldn't break this.
Good news for you, then. Nothing's going to change!
But man I wish it would, for 2.0 that is. I've been hit at least
half-a-dozen times in the past year by missing break statements in my D
code. And I have a C++ background! So it's not about familiarity. It
bites me when I'm coding C++ just as frequently. It's simply a C/C++
mis-feature that D failed to correct.
--bb
More information about the Digitalmars-d
mailing list