How to return 0 in this function?

1
2
3
4
5
6
7
8
9
10
11
12
double MeasureCornerAngle(int nCoord,const double coord[],int index)
{
	if (index < 1 || index > nCoord*2-2)
    {
         return 0.0;
    }
        else
    {
         do something,get a value and use the value when this function is called.
    }

}


This function must return 0.0 if the given index is smaller than 1 or greater than the number of nCoord*2-2.But I cannot write it this way,because I got a warning'Control may reach end of non-valid function'

How should I organize my code to meet the above requirement?
Last edited on
Well this can be simply solved in several ways.

the value 0.0 is the same as 0, therefore changing it to zero will still work. Like so:
1
2
3
4
5
6
7
8
9
10
11
12
13
double MeasureCornerAngle(int nCoord,const double coord[],int index)
{
	if (index < 1 || index > nCoord*2-2)
    {
         return 0;
    }
        else
    {
         return 1.0; //This can be any value that you choose
    }

}


you could also assign zero to a variable and return that variable instead.
Last edited on
Topic archived. No new replies allowed.