Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C warning 'return' with no value, in function returning non-void

Tags:

c

warnings

I have this warning.

warning : 'return' with no value, in function returning non-void.

like image 863
ambika Avatar asked Mar 11 '10 04:03

ambika


1 Answers

You have something like:

int function(void)
{
    return;
}

Add a return value, or change the return type to void.

The error message is very clear:

warning : 'return' with no value, in function returning non-void.

A return with no value is similar to what I showed. The message also tells you that if the function returns 'void', it would not give the warning. But because the function is supposed to return a value but your 'return' statement didn't, you have a problem.

This is often indicative of ancient code. In the days before the C89 standard, compilers did not necessarily support 'void'. The accepted style was then:

function_not_returning_an_explicit_value(i)
char *i;
{
    ...
    if (...something...)
        return;
}

Technically, the function returns an int, but no value was expected. This style of code elicits the warning you got - and C99 officially outlaws it, but compilers continue to accept it for reasons of backwards compatibility.

like image 67
Jonathan Leffler Avatar answered Nov 15 '22 10:11

Jonathan Leffler