🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Bala Rajaraman Fri, 05 Jan 1990 02:17
Enumeration Problem (Simple)
#488
Author: Bala Rajaraman
Date: Fri, 05 Jan 1990 02:17
34 lines
1281 bytes
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
Re: Enumeration Problem (Simple)
#489
Author: Doug Schmidt
Date: Fri, 05 Jan 1990 05:47
15 lines
1164 bytes
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads