C puzzle

T.C. Zhao svec5 at menudo.uh.edu
Thu Jun 20 11:00:11 AEST 1991


In article <4007 at d75.UUCP> thomas at advent.uucp () writes:
>
>       The following is an interesting 'C' puzzle. 
>       Consider this typical switch statement, typical except that 
>       'default' is misspelled 'defalut'! What is interesting is that
>       any C compiler will not and should not give you a syntax error. 
>       Why?  
>
>
>       switch (cmd)
>       {
>              case GO:
>                     ...
>                     break;
>              case STOP:
>                     ...
>                     break;
>              defalut:
>                     printf ("Unknown command\n");
>                     break;
>       }

Well, it depends. If defalut is never referenced, some compilers
with certain switches might produce a warning: unreferenced label
or unreachable code. I have not seen any C compiler like this( it is
my impression that Fortran compiler tends to warn this kind of
unreferenced stuff), but I wish my compiler would warn.



More information about the Comp.lang.c mailing list