Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!deb From: deb@svax.cs.cornell.edu (David Baraff) Newsgroups: comp.lang.c++ Subject: stronger type checking of enums Message-ID: <25740@cornell.UUCP> Date: 3 Mar 89 02:46:43 GMT Sender: nobody@cornell.UUCP Reply-To: deb@cs.cornell.edu (David Baraff) Organization: Cornell Univ. CS Dept, Ithaca NY Lines: 28 I'd like to make a case for stronger type checking of enum's. In cfront 1.2, the following is legal: -------------------- enum color { RED, GREEN, BLUE }; enum fruit { APPLE, PEAR }; color foo() { return PEAR; // I say this should cause a problem } -------------------- A 'PEAR' is of type 'fruit', and not of type 'COLOR', so the above definition of foo should be an error (or at the very least, a warning). I had a function that was of type 'boolean', but accidentally returned some other enum constant. With strong(er) type checking the compiler could easily have determined I had a type error. Why shouldn't enum's have their own type, and why shouldn't the compiler strongly type enum expressions? David Baraff deb@svax.cs.cornell.edu