473,778 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

''warning C4715 not all control paths return a value'' What does it mean?

warning C4715: 'Pow' : not all control paths return a value
warning C4715: 'Sery' : not all control paths return a value

Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. double Pow(double x, int n)
  5. {
  6.     if (n == 0)
  7.         return 1;
  8.     if (n > 0)
  9.         return x * Pow(x, n - 1);
  10.     if (n < 0)
  11.         return Pow(1 / x, -n);
  12. }
  13.  
  14. double Sery(int n, int t)
  15. {
  16.     if (n > 0)
  17.         return Sery(n - 1, t) + Pow(n, t);
  18. }
  19.  
  20. int _tmain(int argc, _TCHAR* argv[])
  21. {
  22.     std::cout << Sery(1, 1) << std::endl;
  23.         return 0;
  24. }
Nov 16 '10 #1
2 7410
hype261
207 New Member
Basically what this is telling you is that your code could potentially return garbage. Take a look at the Sery function.

Expand|Select|Wrap|Line Numbers
  1. double Sery(int n, int t) 
  2.     if (n > 0) 
  3.         return Sery(n - 1, t) + Pow(n, t); 
  4.  
  5. }
What is going to happen if n equals -1. So -1 > 0 will evaluate to false and the statement return Sery(n - 1, t) + Pow(n, t); won't be executed. This is why it is giving you the warning.
Nov 17 '10 #2
donbock
2,426 Recognized Expert Top Contributor
hype261 is right about 'Sery', but the situation is a little more confusing in 'Pow'.
Expand|Select|Wrap|Line Numbers
  1. double Pow(double x, int n) 
  2.     if (n == 0) 
  3.         return 1; 
  4.     if (n > 0) 
  5.         return x * Pow(x, n - 1); 
  6.     if (n < 0) 
  7.         return Pow(1 / x, -n); 
  8. }
The compiler is worried that the last if test might be false, causing execution to fall out of the function without hitting a return statement. You might argue that the previous two if statements guarantee that the last test can't be false, but your compiler is unable to recognize this dependency between these statements.

The following alternative will satisfy the compiler:
Expand|Select|Wrap|Line Numbers
  1. double Pow(double x, int n) 
  2.     if (n == 0) 
  3.         return 1; 
  4.     else if (n > 0) 
  5.         return x * Pow(x, n - 1); 
  6.     else   /* n must be < 0. */
  7.         return Pow(1 / x, -n); 
  8. }
By the way, you might want to change the name of your 'Pow' function so that it won't be confused with the Standard Library 'pow' function.
Nov 17 '10 #3

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"); }
5
8091
by: Dmitriy Lapshin [C# / .NET MVP] | last post by:
Hi all, I think the VB .NET compiler should at least issue a warning when a function does not return value. C# and C++ compilers treat this situation as an error and I believe this is the right thing to do. And I wonder why VB .NET keeps silence and makes such function return some default value instead. Isn't it error-prone? -- Dmitriy Lapshin
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
3
1210
by: John Dann | last post by:
A question that I'm in two minds about - maybe someone more experienced could offer some advice? Let's say I have a method in a class whose function is to generate an image (But it could equally apply to any more complex object that the method might generate.) Then it seems to me that I have two options: 1. Set the image as the return value for the function.
2
2721
jamesd0142
by: jamesd0142 | last post by:
Hi jus messing round with some simple encryption here... main problem is my return value does not get returned to the main process... -------------------------------------------------------------------------- Public Function SimpleCrypt( _ ByVal myVal As String) As String Dim strTempChar As String, i As Integer
7
10815
by: siri11 | last post by:
hi everyone!!!! I have written a function that shud return a decimal value.But I'm getting an error in c#.net(windows Application) which is a build error--->not all code paths return a value.Can anyone plzz suggest why this error is popping up.What does this mean??? Thnks in advance siri
5
11877
by: kenneth6 | last post by:
int Class::function() { if(a>b) { if(c==1) { if(d==2) { return 2; }
4
10283
Markus
by: Markus | last post by:
I have a method that checks whether the passed argument is present in an array. The method needs to return a bool value. Take a look at said method: private bool IPExist(string IP) { // We need to check if the IP exists in the // IP array foreach (string x in IPs) { if (x == IP)
1
3194
by: spartan118 | last post by:
/*Windows Privilage Grant...*/ #include "H:\Profile\Desktop\rawrr\HEADERS.h" #include "H:\Profile\Desktop\rawrr\DEFINITIONS.h" HANDLE screen; int main () { TOKEN_PRIVILEGES NewState; //granting privileges to shut off Windows© Firewall among other things... LUID_AND_ATTRIBUTES luidattr;
0
9464
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10292
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
10122
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
8954
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...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.