Missing default in switch

Robert Pluim rpluim@bigfoot.com
Wed Oct 20 09:57:00 GMT 1999


David R Tribble <david@tribble.com> writes:

> Alex Vinokur wrote:
> > Is there any possibility to make a compiler protest
> > against missing default-word in switch-statement?
> 
> Some do, but none are required to by the ISO standard.
> 
> Sometimes it's irritating when they do issue a warning, though.
> For example:
> 
>     enum Color { RED, BLUE, GREEN };
> 
>     void hue(enum Color col)
>     {
>         switch (col)
>         {
>         case RED:
>             ...do something...
> 
>         case BLUE:
>             ...do something...
> 
>         case GREEN:
>             ...do something...
> 
>         /* No default necessary, i.e., do nothing */
>         }
>     }

Doesn't some incarnation of gcc complain if you don't cover all the
possibilities of the enum in the switch? If so, it should be possible
to extend it to complain about a missing default:.

Robert
-- 
The above are my opinions,
 and my opinions only.


More information about the Gcc-help mailing list