473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

''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 7367
hype261
207 100+
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 Expert 2GB
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
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...
5
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() {...
5
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...
25
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...
3
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...
2
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... ...
7
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...
5
by: kenneth6 | last post by:
int Class::function() { if(a>b) { if(c==1) { if(d==2) { return 2; }
4
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) { ...
1
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;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.