C puzzle

Hubert Yamada yamada at stego.ifa.hawaii.edu
Thu Jun 20 12:13:51 AEST 1991


In article <1991Jun20.010011.18425 at menudo.uh.edu> svec5 at menudo.uh.edu (T.C. Zhao) writes:
>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?  
[Example deleted]
>
>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.

Actually, I don't know of any C compiler that _won't_ tell you about
this error, if you set the warning level reasonably high.  With UNIX
cc, setting the warning level high enough == use lint.  (To avoid
flames: I'm not saying that such C compilers don't exist, or even that
they aren't common, just that none of the compilers that I use have
that problem.)

Unix gcc (1.39): gcc -Wall
	temp.c:16: warning: label `defalut' defined but not used

Sun OS 4.1 lint: lint
	temp.c(16): warning: defalut unused in function xxx 

Microsoft C 6.0: cl -WX
	temp.c(20) : warning C4102: 'defalut' : unreferenced label

PC lint (Gimpel Software): lint
	temp.c(19) : Info 744: switch statement has no default
	temp.c(20) : Warning 563: defalut (line 16) not referenced
-- 
****************************************************************************
Hubert Yamada
Internet: yamada at galileo.ifa.hawaii.edu (or yamada at uhunix.uhcc.hawaii.edu)
Bitnet: yamada at uhunix.bitnet



More information about the Comp.lang.c mailing list