Possible bug in the SUN C compiler
William Aitken
aitken at svax.cs.cornell.edu
Tue Jun 14 05:34:27 AEST 1988
Yesterday, I was compiling some code and had a piece of code that I didn't
think could possibly compile compile without error. In fact, lint didn't
even complain. The problem is that the compiler allows one to use variables
of struct type as switch selectors. This can't be right. Can it??? The
reason I don't think its right is that there is no way to specify the case
labels -- after all there are no anonymous structure constants in C.
Furthermore, some quick investigation suggests that what the compiler does is
to select on the first element of the structure. Below is a code fragment
which compiles without error on SUN OS version 3.5. (incidentally Mt. Xinu
4.3 complains about it)
struct splat {
int foo_foo;
int foo_bar;
} foo;
unsigned int
convfoo(bar)
struct splat bar;
{
switch (bar) {
case 1:break;
default:foo = bar;break;
}
return 0;
}
The question is this a bug, or this behavior mandated by K&R or the proposed
ANSI standard. If the latter, why is such a kludge mandated?
--- Bill.
William E. Aitken <aitken at svax.cs.cornell.edu> (607)257-2542(h)
{uw-beaver,ihnp4,vax135,decvax}!cornell!aitken (607)255-4222(o)
aitken at crnlcs.BITNET 700 Warren Rd. #20-2A, Ithaca, NY
42 26'30" N 76 29'00" W 4148 Upson Hall
More information about the Comp.lang.c
mailing list