C puzzle

Martin Weitzel martin at mwtech.UUCP
Sun Jun 23 00:56:26 AEST 1991


In article <13544 at uhccux.uhcc.Hawaii.Edu> yamada at stego.ifa.hawaii.edu (Hubert Yamada) writes:
>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. 
[...]
>>
>>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 at mwtech.UUCP, voice: 49-(0)6151-6 56 83



More information about the Comp.lang.c mailing list