Microchip
直播中

邢党铿

7年用户 189经验值
私信 关注
[问答]

非void函数解决方案帮助结束时隐式返回

大家好,我已经写了一些代码,看一个称为位置的子例程的输出,它返回一个浮点P。这个浮标被与一个叫做FRORORSELSET子程序的其他输入进行比较,我让这些FroRoSLead选项对应于浮点(F1,F2和F3)。其中,“地板”P最接近.FY.位置子程序是ADC中的一个输出,并将其转换成米的测量值。在构建时,我得到了下面的“非空洞函数结束时的隐式返回”。ENT if语句。代码是相当基本的,可以更流利的提示,将不胜感激。

以上来自于百度翻译


      以下为原文

    Hello All,
I have written some code, to look at the output of a subroutine called position, which returns a float p.
This float is compared to other input from a subroutine called floor_select, I have made these floor_select options correspond to floats (f1,f2 and f3) .
A calculation is made to determine which "floor" the p is closest to.

FYI the position subroutine is an out put from an ADC and converts its to a measurement in meters.
I have been getting the following when building,

"Implicit return at end of non-void function"

I have a general understanding that it might be do to with the 3 different if statements.
The code is fairly basic and could be more eloquent
Any hints would be greatly appreciated.

short Floor_Comparision (float p)
{
position; //Runs position subroutine to gain a value of the float "p"
float diff; //Float "diff" being the difference between selected floor and position "p"
short w;
int floor_selected;
float floor_level;
                                //Tolerance and Individual Floor Floats
float tole = 0.0125; //Allowable tolerance difference of +/- 0.0125 meters
float f1 = 0.0000; //Floor 1 Float of 0.0000 Meters
float f2 = 3.0000; //Floor 2 Float of 3.0000 Meters
float f3 = 6.0000; //Floor 3 Float of 6.0000 Meters

                                //For the particular floor_select short int
                                //A corresponding "floor_level" is given as a float
if (floor_selected == 1)
    {
    floor_level == f1;
    }
if (floor_selected == 2)
    {
    floor_level == f2;
    }
if (floor_selected == 3)
    {
    floor_level == f3;
    }
                                //Comparison Calculation
floor_level - p == diff; //Requested floor height - current height = difference in height
                                //Either a positive or negative number
if (diff > 0.125) //If Difference is greater than +0.0125m
    { //Requested floor height is higher current position
    w = 1; //Set w =1 (Lift Run and Up-wards )
    return w;
    }
if (diff < -0.125) //If Difference is less than -0.0125m
    { //Requested floor height is lower current position
    w = 2; //Set w =2 (Lift Run and Down-wards )
    return w;
    }
if (-0.125 <= diff <= 0.125) //If Difference is greater than or equal to -0.0125m
    { //Or Difference is less than or equal to +0.0125m
    w = 0; //Set w =0 (Lift Stop)
    return w;
    }
}

回帖(7)

陈杰

2018-9-20 09:53:17
我不知道如果没有“IF”条件会发生什么?

以上来自于百度翻译


      以下为原文

    I wonder what happens if none of the "if" conditions are met ?
举报

杨晓静

2018-9-20 09:59:54
“如果(-0.125& lt;=diff& lt;=0.125)/ /如果差值大于或等于-0.0125M”,我认为这并不是OP认为它所做的。看起来有点像BASIC。

以上来自于百度翻译


      以下为原文

    "if (-0.125 <= diff <= 0.125) //If Difference is greater than or equal to -0.0125m"
 
I don't think this does what the OP thinks it does either. Looks a bit like BASIC.
举报

李涛

2018-9-20 10:18:48
重写该代码,使最终返回为W.例如(x=1)w=7;否则,如果(x=2)w=11;否则w=13;返回w;

以上来自于百度翻译


      以下为原文

    Rewrite the code so that the final return is w.
e.g.
if (x==1) w=7;
else if(x==2) w=11;
else w=13;
return w;
举报

李涛

2018-9-20 10:24:00
快速回复不工作。

以上来自于百度翻译


      以下为原文

    Quick reply not working again.
举报

更多回帖

发帖
×
20
完善资料,
赚取积分