简体   繁体   English

如何解决“控件到达非void函数结束”警告?

[英]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 但出现错误”,

  • Your function 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.

相关问题 控制到达非空 function 的末尾。 如何解决这个问题? - control reaches end of non-void function. How to solve this? 警告:控制到达非无效功能的结尾 - warning: control reaches end of non-void function 警告:控制到达非空函数(gtk)的结尾 - warning: control reaches end of non-void function (gtk) 如何修复“错误:控制到达非空函数结束”? - How to fix "error: control reaches end of non-void function"? 当调用带有警告“控制到达非空函数结束”的函数时(实际上)会发生什么? - What (actually) happens, when a function with the warning "control reaches end of non-void function" is called? “警告:控制到达非空函数的末尾”,但实际上该函数被声明为int并返回一个int - “warning: control reaches end of non-void function” but actually the function is declared as int and return an int 为什么主函数会出现“控制到达非空函数结束”的警告? - Why a warning of “control reaches end of non-void function” for the main function? 警告:控制到达非空函数的结尾 [-Wreturn-type] - warning: control reaches end of non-void function [-Wreturn-type] Carboard.c:12:1:警告:控制权到达非空函数的结尾[-Wreturn-type] - Carboard.c:12:1: warning: control reaches end of non-void function [-Wreturn-type] 警告:控制到达非空函数的结尾 [-Wreturn-type] - warning: control reaches end of non-void function [-Wreturn-type]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM