switch()

Daniel Murphy yebbliesnospam at gmail.com
Wed Feb 19 01:42:19 PST 2014


"Steven Schveighoffer"  wrote in message 
news:op.xbhnw5rbeav7ka at stevens-macbook-pro.local...

> It may not be mindless. Most people who want to handle the default case do 
> it. It's usually not so much "I didn't think of handling other values," 
> it's more "I never expect other values to come in, go away annoying 
> compiler error."

So why not put an assert(0) in instead of a break?  Tell the compiler that 
you're assuming there are no other possible values.  This is obviously the 
right thing to do here, and even if you ignore it the compiler _is_ trying 
to help you.

> I think it's the same as saying you have to always have an else clause 
> after an if statement, even if it's "else {}"

If 'if' was primarily used for the same thing that switch is, this would be 
perfectly reasonable. 



More information about the Digitalmars-d mailing list