473,776 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

not all control paths return a value??

79 New Member
Expand|Select|Wrap|Line Numbers
  1. int Class::function()
  2. {
  3.      if(a>b)
  4.      {
  5.           if(c==1)
  6.           {
  7.                if(d==2)
  8.                {
  9.                     return 2;
  10.                }
  11.                else
  12.                {
  13.                     return 1;
  14.                }
  15.           }
  16.           if(c==2)
  17.           {
  18.                if(d==2)
  19.                {
  20.                     return 2;
  21.                }
  22.                else
  23.                {
  24.                     return 1;
  25.                }
  26.           }
  27.      }
  28.      else if(a<b)
  29.      {
  30.           if(d>=e)
  31.           {
  32.                return -1;
  33.           }
  34.           else
  35.           {
  36.                return -2;
  37.           }
  38.      }
  39.      else
  40.      {
  41.           if(c=1)
  42.           {
  43.                return 0;
  44.           }
  45.      }
  46. }
Q.1
After I run the above codes, [warning C4715: "not all control paths return a value"], what does it mean? how can I solve the problem?

Q.2
And:
"1>LINK : C:\Console\Debu g\Test.exe not found or not built by the last incremental link; performing full link"
What does it mean?
Apr 6 '08 #1
5 11876
JosAH
11,448 Recognized Expert MVP
Q.1
After I run the above codes, [warning C4715: "not all control paths return a value"], what does it mean? how can I solve the problem?

Q.2
And:
"1>LINK : C:\Console\Debu g\Test.exe not found or not built by the last incremental link; performing full link"
What does it mean?
A1: suppose a > b and !(c == 1 || c == 2), your function doesn't return anything.

A2: was that build your first build? If so, ignore the message.

kind regards,

Jos
Apr 6 '08 #2
kenneth6
79 New Member
A1: suppose a > b and !(c == 1 || c == 2), your function doesn't return anything.

A2: was that build your first build? If so, ignore the message.

kind regards,

Jos
HEY! thx ~

If i ensure that the function returned and assigned to c must be either 1 or 2, but not others. can I ignore these errors?
Apr 6 '08 #3
JosAH
11,448 Recognized Expert MVP
HEY! thx ~

If i ensure that the function returned and assigned to c must be either 1 or 2, but not others. can I ignore these errors?
Sure, if your compiler still generates code for it; otherwise simply add a dummy
return statement:

Expand|Select|Wrap|Line Numbers
  1. if (a > b) {
  2.    if (c == 1) { ... }
  3.    if (c == 2) { ... }
  4.    return 0; /* dummy return; not reached */
  5. }
  6.  
kind regards,

Jos
Apr 6 '08 #4
kenneth6
79 New Member
Sure, if your compiler still generates code for it; otherwise simply add a dummy
return statement:

Expand|Select|Wrap|Line Numbers
  1. if (a > b) {
  2.    if (c == 1) { ... }
  3.    if (c == 2) { ... }
  4.    return 0; /* dummy return; not reached */
  5. }
  6.  
kind regards,

Jos
THanks a lot ! Jos ~ ~
Apr 6 '08 #5
JosAH
11,448 Recognized Expert MVP
THanks a lot ! Jos ~ ~
You're welcome of course; if you make sure you can ensure that c == 1 or c ==2
then the following will be fine too:

Expand|Select|Wrap|Line Numbers
  1. if (a < b) {
  2.    if (c == 1) { ... }
  3.    else { ... }
  4. }
  5.  
In the else part is is implicitly assumed that c == 2 which you took care of.
This little trick gets rid of that spurious 'return 0' thing at the end.

kind regards,

Jos
Apr 6 '08 #6

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

Similar topics

6
3440
by: Bruce W.1 | last post by:
The intent of my web service is an RSS feed from a blog. Originally I used a StringBuilder to make the XML and returned a string from the webmethod. But this doesn't display properly in IE. So now I'm trying an XmlTextWriter instead. I whipped-up another webservice based on this: http://www.codeproject.com/aspnet/RSSviaXmlTextWriter.asp?print=true This example isn't set up strictly as a webservice. It seems to output to an aspx...
5
6759
by: n_o_s_p_a__m | last post by:
Can't compile. Does this mean that all functions that throw exceptions must be of return type void? examples: // won't compile: "not all code paths return a value" public override int Run() { throw new Exception("exception thrown"); }
12
4131
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport) {
4
13011
by: OutdoorGuy | last post by:
Greetings, I am attempting to compile the code below, but I am receiving an error message when I do so. The error message is: "CSO161: 'Forloop.CalcAvg(int)': Not all code paths return a value". Any idea as to what I'm doing wrong? I'm sure it's something simple. Thanks in advance! public class ForLoop
3
8645
by: Oberon | last post by:
How do I deal with this? I am getting an error for each get in the Game class (see code below). In the simplified example below I have reduced this to just 3 fields, one which can be NULL. I have added 3 records to the table and ran the program but it fails with the error above. The application is supposed to create the hashtable of records as a static feature which will be permanently available to my application. To demonstrate that...
2
2370
by: Alex | last post by:
Hi. I need some help on this. I have a user control (a header) in my root directory, and all my pages use that control. Then a created a folder (in my root directory) and put a new page inside it, and that page use the same control, but this time the control can't find it's images and resources because it is trying to find it in the same folder instead of the root directory. Now, I know that I can change the control image's relative paths...
7
11616
by: Robert | last post by:
I have the function below. it returns a "simpleresult" which I've also included the definition of below. In VS2005 (after upgrading the project), I get a warning indicating that Function 'CloseVantive' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used. The code runs fine. But why do I get this message? How do i get rid of it? The only thing I found is if i add a...
25
2571
by: guy | last post by:
i have inherited the following migrated vb6 code (vb2005) but i DONT get the "not all paths return a value" squiggly - is this a 'feature' of on error goto? Private Function CreateFolder(ByVal sFileName As String) As Boolean On Error GoTo Errors 'Create it if necessary If Directory.Exists(sFileName) = False Then
1
1378
by: UJ | last post by:
I am doing development on a machine and everything was working fine. The name of the project was ECS to I made all my references as ~/ECS/... Worked great. Put it on the final server running 2003/IIs 6and it bitched it couldn't find the directory. I created a virtual directory, it complained because web.config wasn't there. I removed the ECS from all the references and it works great on both my devo and the final machine.
0
9628
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
10120
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
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
8952
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
7471
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
6722
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();...
1
4031
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
3
2860
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.