简体   繁体   中英

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 . The code in question [with the if-statement and body of if-statement omitted as ] is of the form:

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. 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 .

It can be caused by control statements such as if-statements and missing return statements.

To answer " I specified the return value of the function as void but I am getting an error ",

  • Your function osa_odm_init returns a RC_Code_t , not void . The void is in the arguments, indicating no arguments.

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. 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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM