Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!uwvax!tank!ncar!asuvax!anasaz!qip!shino From: shino@qip.UUCP (Rei Shinozuka) Newsgroups: comp.lang.c Subject: enum type checking and switches question Message-ID: <1116@qip.UUCP> Date: 25 Oct 89 20:24:05 GMT Reply-To: shino@qip.UUCP (Rei Shinozuka) Organization: Anasazi Inc, Phoenix AZ Lines: 39 I am new to this newsgroup, so apologies if the following posting is innapropriate/naive. Why is it that cc does not perform enum type checking for switches? For assignments and comparisons, the compiler makes sure that the enum types match, as in the if statement below. enum bar { ONE, TWO } foo; int baz; if (foo == ONE) /* OK both of type enum bar */ ... if (baz == ONE) /* warning incompatible types */ ... Given the same declarations above, the compiler doesn't seem to care about the enum types of the switch expression and constant expression. switch(foo){ case ONE: /* OK both or type enum bar */ ... }/*end switch*/ switch(baz){ case ONE: /* no complaints, though types differ */ ... }/*end switch*/ It seems to me that the compiler has enough information to flag a type incompatibility as it does in the first example with the second if. Is there a reason the compiler doesn't do this in the case (bad pun) of switches? thanks, -rei