This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Missing default in switch
T.E.Dickey wrote:
>
> In comp.std.c David R Tribble <david@tribble.com> wrote:
>
>> Some compilers (and some lint programs) allow you to add a special
>> comment where the missing default goes to indicate that the default
>> case is omitted on purpose.
>
> otoh, if you _do_ supply a 'default:', then some compilers will
> generate more compact code (in addition to not warning about the
> missing case).
>
> -- that's probably better than a comment...
I agree. I usually supply a default, even if all it does is a break.
But I don't see how that can lead to more optimized code. What's the
difference in the code generated for [A] and [B] in:
/* [A] */
switch (c)
{
case 1:
stmt1;
case 2:
stmt2;
case 3:
stmt3;
}
/* [B] */
switch (c)
{
case 1:
stmt1;
case 2:
stmt2;
case 3:
stmt3;
default:
break;
}
I can't see how the code would be any different after optimization.
-- David R. Tribble, david@tribble.com, http://www.david.tribble.com --