I’m a newbie at C, I am working on someone else’s code and I am trying to get rid of a warning that looks like this:
warning: function expects to return value: myfunc
myfunc is declared like this, (I believe it defaults to int)
myfunc(int id, int age) {
...
return;
}
So I try to put void behind myfunc so that it looks like this
void myfunc(int num, int age) {
I get an error:
identifier redeclared: myfunc
current : function() returning void previous: function() returning int : "students.c", line 233
But when I go to line 233 of students.c, this is just the first place that I actually call the function. Why is this happening?
I know I could change return to return 0; and then define myfunc as int. But when this function is called, it’s not assigned to anything, it’s just executed like myfunc(current_id, age); (not int i = myfunc(... for example).
In a situation like this, would it best not to use void? Is it ok to use return; in a void function?
Thanks!
The function
myfunc()is declared with no return type (somewhere):or there is no declaration at all, so it defaults to an
intreturn type. When you specifyvoidat the definition:it does not match the declaration. Change, or add, the declaration:
You don’t need to explicitly write
return;in a function with avoidreturn type, but you can if you wish.