473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

enum value not handled in switch

32
This post went around back in January. I need some clarification.

I have an enum declaring 30 enumerated values

a=0
b=1
c=2
etc

I have a switch statement that I don't want to use all 30 enumerations in.

I get the compiler error "enumeration value not handled in switch"
I am using g++ on a unix box.

The -Wswitch compiler option that was suggested in the previous posting is available to me but it does not supress the warning. Using it does not suppress the error.
Actually the previous post said -Wswitch-enum which I don't see in the gnu manpage.

What is the correct option to use -Wswitch or -Wswitch-enum? and where does it go in the makefile. In CFLAGS or LDFLAGS???

The default case does stop the warnings, but, if the compiler option is doing what it's supposed to do, I shouldn't need the default case.

Thanks

emp1953
Nov 29 '07 #1
1 18106
weaknessforcats
9,208 Expert Mod 8TB
An enum is not a list if integer variables. It is a list of names for integer values so you can avoid hard-coded values in your program.

Therefore, you cannot switch on an enum.

In C++, you have to create a variable and switch on that:
Expand|Select|Wrap|Line Numbers
  1. enum Value {A,B};
  2.  
  3. int main()
  4. {
  5.     Value arg = A;
  6.     switch (arg)
  7.     {
  8.        case A:
  9.            break;
  10.  
  11.         default:
  12.             break;
  13.     }
  14. }
  15.  
C is different. It doesn't see Value as a type. Here you have to typedef:
Expand|Select|Wrap|Line Numbers
  1. typedef enum {A,B} Value;
  2.  
  3. int main()
  4. {
  5.     Value arg = A;
  6.     switch (arg)
  7.     {
  8.        case A:
  9.            break;
  10.  
  11.         default:
  12.             break;
  13.     }
  14. }
  15.  
Nov 30 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: AngleWyrm | last post by:
"The C++ Programming Language" by Bjarne Stroustrup, copyright 1997 by AT&T, section 4.8 (pp 77): "A value of integral type may be explicitly converted to an enumeration type. The result of such a...
8
by: Imran | last post by:
Hello All I have a enum decla like this enum Days // Declare enum type Days { saturday, // saturday = 0 by default sunday = 0, // sunday = 0 as well monday, ...
5
by: DJTB | last post by:
Dear Group, I'd like to check if a value is defined in an enum. Example: ------------------------------------------------------ typedef enum { A_VALUE = 1,
9
by: ccwork | last post by:
Hi all, We can define some magic number with #define: #define OPERATION_1 0x00000001 #define OPERATION_2 0x00000002 #define OPERATION_3 0x00000003 .... We can also do that with enum: enum...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
13
by: Adam Blair | last post by:
Is it possible to bind a switch statement to an Enum such that a compile-time error is raised if not all values within the Enum are handled in the switch statement? I realise you can use default:...
8
by: tony | last post by:
Hello! I have below a for loop and a switch in the for loop. I have also a enum called colBlowStep with some values. I have also an array called m_columnBlowStep with some strings. All items in...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
8
by: Mark P | last post by:
I'm working on a project where I have something like enum Modes {mode_a, mode_b, ...}; Due to project spec changes, the number of Modes has increased several times. There are a few places...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.