Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!ox.com!math.fu-berlin.de!unido!mikros!mwtech!martin From: martin@mwtech.UUCP (Martin Weitzel) Newsgroups: comp.lang.c Subject: Re: C puzzle Message-ID: <1173@mwtech.UUCP> Date: 22 Jun 91 14:56:26 GMT References: <4007@d75.UUCP> <1991Jun20.010011.18425@menudo.uh.edu> <13544@uhccux.uhcc.Hawaii.Edu> Reply-To: martin@mwtech.UUCP (Martin Weitzel) Organization: MIKROS Systemware, Darmstadt/W-Germany Lines: 46 In article <13544@uhccux.uhcc.Hawaii.Edu> yamada@stego.ifa.hawaii.edu (Hubert Yamada) writes: >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. [...] >> >>Well, it depends. If defalut is never referenced, some compilers >>with certain switches might produce a warning: unreferenced label [...] >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. [...] Using lint only works if you are in the happy situation that your compiler (together with its header-files) is not yet so much ANSI-fied that your lint becomes unusable. (I'm sometimes forced to use such a beast; it's halfway down the road to ANSI-C. I like to profit from function prototypes, but sadly enough the lint on this system is the "old" one, which doesn't know anything of all that.) BTW: Here's another bug with a switch statement involved, I've once been tracing this for some hours: enum { RED, BLUE, GREEN } colour; ... /* assign valid value to colour */ ... switch (colour) { RED: ....; break; BLUE: ....; break; GREEN: ....; break; } Of course, finding the bug involved isolating this piece of code and finding out why `colour' changed its value away from one of `RED', `BLUE', or `GREEN', which I *thought* was the reason that no branch of the switch got ever executed ... (I confess: I didn't see the light until I had some printf-s immediatly before and after the switch which showed the value of `colour' in decimal and proved it beeing correct all the time.) -- Martin Weitzel, email: martin@mwtech.UUCP, voice: 49-(0)6151-6 56 83