472,800 Members | 1,118 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,800 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 17776
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.