473,672 Members | 2,945 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strange compilation warning

The following code:

enum Foo { one, two };
int Bar(Foo foo)
{
switch (foo)
{
case Foo.one:
return 7;
case Foo.two:
return 4;
}
}

gives a compilation warning "not all paths return a value"

surely this is spurious though? - there is no path I can see that does not
return a value

Andy
Sep 4 '07 #1
3 1251
there is no path I can see that does not return a value
How about:
Foo foo = (Foo) 17; // this works just fine
Bar(foo); //boom

Best option: add a
default: throw new ArgumentExcepti on();
line...

Marc
Sep 4 '07 #2
"Marc Gravell" <ma**********@g mail.comwrote in message
news:u3******** ******@TK2MSFTN GP04.phx.gbl...
>there is no path I can see that does not return a value
How about:
Foo foo = (Foo) 17; // this works just fine
Bar(foo); //boom

Best option: add a
default: throw new ArgumentExcepti on();
line...

Marc
Ooh - I didn't know you could cast an int to an enum even if it was out of
range

Thanks Marc

Sep 4 '07 #3
Andy Fish wrote:
"Marc Gravell" <ma**********@g mail.comwrote in message
news:u3******** ******@TK2MSFTN GP04.phx.gbl...
>>there is no path I can see that does not return a value
How about:
Foo foo = (Foo) 17; // this works just fine
Bar(foo); //boom

Best option: add a
default: throw new ArgumentExcepti on();
line...

Ooh - I didn't know you could cast an int to an enum even if it was out of
range
C# enum is almost just an int.

If I were to guess at why, then I would say that it is necesarry
to support using multiple values in one variable (flags).

Arne
Sep 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3343
by: Dan | last post by:
Hi, I have a problem using an aspx page with a Control on it. I get the following error message Compiler Error Message: CS1595: 'Test.Class2' is defined in multiple places; using definition from 'c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\root\1f575646\ad3a161b\assembly\dl2\57ca505e\044565c0_f84fc401\Test1.DLL' The problem is that the control is defined in two different assemblies
2
1717
by: shaun roe | last post by:
Following up from my earlier post, where I pursued the line I outlined. Here is the MYFunc class implementation: MyFunc::MyFunc(int i):m_i(i){ ostringstream os; os<<"This number is "<<m_i; m_result = os.str(); }
6
9794
by: alban | last post by:
Hello I have got some problems of compilation on a AIX IBM, I use the XLC compilator (And I can't install another one). I try to compile code Pro*c ".pc" (oracle), I need do a pre-compilation after the pre-compilation with the my makefile I get the files ".c" After this a get also the objects files ".o", but no linkage ! and I can't have the exec file ! I have got some errors how I dont understand really :
6
2098
by: subramanian | last post by:
Consider the following program: #include <stdio.h> void myfn(const int **a) { static int i, j, k; a = &i; a = &j;
1
3477
by: Zbigniew | last post by:
Hi, Compiler: GCC 3.3.5 OS: SuSE Linux (Kernel: 2.6.11) I reorganized my source code and now almost all my header files went to "Include" folder. Now when compiling with -I option I have plenty of problems with system include files: "conflict with previous declaration"
2
3272
by: f0zzyNUE | last post by:
hi everyone, currently we are testing the performance our application (asp.net based CMS) ... for that reason we wrote a "spider" that starts webrequests for all relevant pages which results in filling the pageoutputcache on server side. so far so good. if we start one spider at once our application works fine, but if we run more than one spider tool at the same time the asp.net process works for a few minutes returning correct http...
2
3873
by: Hendrik Schober | last post by:
Hi, this piece of code namespace { template< typename T > struct X {}; template< typename T > struct Y {};
3
1811
by: Richard Weeks | last post by:
My question, stated as simply as possible, is: must a constraint violation, as defined by the standard, cause compilation to halt? I believe that in the presence of a constraint violation, at least one diagnostic is required, which, at the discretion of the compiler writer, may be either an "error" or a "warning." Generally however, an error halts compilation and a warning does not. This would seem to imply that it is up to the compiler...
9
1390
by: Larry | last post by:
I was testing the buffer size of system call, read(), and found a strange error on Ubuntu 7.10 server. The code is attached. If the BUFFSIZE is set to from 128 to 255, the code will produce an error as read error: Success If the if statement (and the perror) is removed, the error disappears. I have tried the same program on Sun Solaris 5.10 and got the same results.
0
8498
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8940
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8694
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7458
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6251
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5718
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4237
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4434
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2084
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.