473,513 Members | 2,881 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 1247
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 ArgumentException();
line...

Marc
Sep 4 '07 #2
"Marc Gravell" <ma**********@gmail.comwrote in message
news:u3**************@TK2MSFTNGP04.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 ArgumentException();
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**********@gmail.comwrote in message
news:u3**************@TK2MSFTNGP04.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 ArgumentException();
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
3333
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' ...
2
1710
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
9777
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...
6
2087
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
3471
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
3260
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...
2
3866
by: Hendrik Schober | last post by:
Hi, this piece of code namespace { template< typename T > struct X {}; template< typename T > struct Y {};
3
1802
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...
9
1378
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...
0
7269
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...
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7123
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5701
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...
0
3248
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...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.