[英]How to solve the “control reaches end of non-void function” warning?
I have been getting a compiler error control reaches end of non-void function
.我一直在得到一个编译器错误control reaches end of non-void function
。 The code in question [with the if-statement and body of if-statement omitted as ⋯
] is of the form:有问题的代码 [if 语句和 if 语句的主体省略为⋯
] 的形式如下:
extern RC_Code_t osa_odm_init (void)
{
if ( ⋯ )
{
⋯
⋯
return (RC_OK);
}
}
I specified the return value of the function as void
but I am getting an error.我将函数的返回值指定为void
但出现错误。 How to fix this?如何解决这个问题?
The control reaches end of non-void function
warning occurs when that function return type is not void, but the function can reach the end without a return
.当该函数返回类型不是 void 时,会发生control reaches end of non-void function
的结尾,但该函数可以在没有return
情况下到达结尾。
It can be caused by control statements such as if-statements and missing return statements.它可能是由控制语句(例如 if 语句和缺少 return 语句)引起的。
To answer " I specified the return value of the function as void but I am getting an error ",要回答“我将函数的返回值指定为 void 但出现错误”,
osa_odm_init
returns a RC_Code_t
, not void
.您的函数osa_odm_init
返回RC_Code_t
,而不是void
。 The void
is in the arguments, indicating no arguments. void
在参数中,表示没有参数。 The actual cause is that it returns RC_Code_t
, but the return
is only here if the if-statement is true, you are missing the return
if the if-statement fails.实际的原因是,它返回RC_Code_t
,但return
是只有在这里,如果if语句是真的,你缺少的return
,如果if语句失败。 The edited code should be编辑后的代码应该是
extern RC_Code_t osa_odm_init (void)
{
if ( odmInitFlag == BOOL_FALSE )
{
........
........
return (RC_OK);
}
// This section runs if ( odmIntFlag != BOOL_FALSE )
// In your original code, you omitted the return
return RC_ERROR; // Edit: Or return another RC_Code_t result
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.