Path: utzoo!attcan!uunet!husc6!bbn!rochester!cornell!aitken
From: aitken@svax.cs.cornell.edu (William Aitken)
Newsgroups: comp.lang.c
Subject: Possible bug in the SUN C compiler
Message-ID: <18266@cornell.UUCP>
Date: 13 Jun 88 19:34:27 GMT
Sender: nobody@cornell.UUCP
Reply-To: aitken@cs.cornell.edu (William Aitken)
Followup-To: comp.lang.c
Distribution: comp
Organization: Cornell Univ. CS Dept, Ithaca NY
Lines: 36

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         (607)257-2542(h)
  {uw-beaver,ihnp4,vax135,decvax}!cornell!aitken      (607)255-4222(o)
  aitken@crnlcs.BITNET               700 Warren Rd. #20-2A, Ithaca, NY
  42 26'30" N 76 29'00" W                              4148 Upson Hall