I am getting warning: control reaches end of non-void function.
I have a recursive function that looks like this:
unsigned long FUNCTION (....) {
if (something) {
return 1;
}
else if (something2) {
if(thing) {
FUNCTION(....);
}
else
return 0;
}
else {
return 0;
}
}
I can't just put return 0; at the end of the function because it ends up making my program do what I don't want it to. How do I make the warning go away?
The branch calling FUNCTION(...)
doesn't return anything. As a result, if this branch is taken your function has undefined behavior. What needs to be returned can't be determined from your code: you'll have to come up with that.
Note that FUNCTION
normally indicates that the name is a macro: there are a few conventions how things are named to avoid confusion. You can call your functions with all uppercase letters but it may not be a good idea.
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.