PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 28, 2022

[FIXED] How to solve the "control reaches end of non-void function" warning?

 April 28, 2022     c, compiler-warnings, function, warnings     No comments   

Issue

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?


Solution

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
}


Answered By - Ṃųỻịgǻňạcểơửṩ
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing