[gnu.g++] Enumeration Problem

rajarar@hubcap.clemson.edu (Bala Rajaraman) (01/05/90)

Stroustrup's C++ book indicates that if in a switch only a few of the 
enumerated values are handled the compiler issues a warning [pg. 64-65].
	In the following program the g++ compiler neither issues a warning, 
nor does it prevent me from assigning an arbitrary value to a variable of 
an enumerated type.
-------------------------------------------------------------------------
#include <stdio.h>
#include <stream.h>

main()

{
enum keys {ASM,AUTO,BREAK};

keys key;

key = 4;
switch (key) {
	case ASM:
		break;
	case AUTO:
		break;
	}
cout << "KEY = " << key << "\n";
}
-------------------------------------------------------------------------
Is this feature not available in g++ ??
	If this is a trivial question, I apologize. I do not have the
GNU G++ User Guide as yet.
	Thanks
	Bala
:-)
rajarar@hubcap.clemson.edu

schmidt@glacier.ics.uci.edu (Doug Schmidt) (01/05/90)

In article <7570@hubcap.clemson.edu>, rajarar@hubcap (Bala Rajaraman) writes:
>
>Stroustrup's C++ book indicates that if in a switch only a few of the 
>enumerated values are handled the compiler issues a warning [pg. 64-65].
>	In the following program the g++ compiler neither issues a warning, 
>nor does it prevent me from assigning an arbitrary value to a variable of 
>an enumerated type.

Try using the -Wall -Wenum-clash flag with g++.  This will warn about
the unused enum value in the switch and the assignment of an integer
to an enumeral.

  Doug
--
Douglas C. Schmidt