Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!caen!spool.mu.edu!uunet!munnari.oz.au!uhccux!stego!yamada From: yamada@stego.ifa.hawaii.edu (Hubert Yamada) Newsgroups: comp.lang.c Subject: Re: C puzzle Message-ID: <13544@uhccux.uhcc.Hawaii.Edu> Date: 20 Jun 91 02:13:51 GMT References: <4007@d75.UUCP> <1991Jun20.010011.18425@menudo.uh.edu> Sender: news@uhccux.uhcc.Hawaii.Edu Organization: Institute for Astronomy, Hawaii Lines: 40 In article <1991Jun20.010011.18425@menudo.uh.edu> svec5@menudo.uh.edu (T.C. Zhao) writes: >In article <4007@d75.UUCP> thomas@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@galileo.ifa.hawaii.edu (or yamada@uhunix.uhcc.hawaii.edu) Bitnet: yamada@uhunix.bitnet