I’ve a problem with the returned value of a C function.
I’ve a main function in which I call the function “send” in this way;
int go_On;
go_On = send(VOTE_REQUEST, 1);
The “send” function is composed as follows:
int send(int msg, int flag) {
// inizialization of some parameters;
if (msg == VOTE_REQUEST) {
// Do some operations...
result = send(VOTE_COMMIT, 1);
}
else if (msg == VOTE_COMMIT) {
// Do some other operations...
return 10;
}
}
where VOTE_REQUEST and VOTE_COMMIT are constants declared at the beginning of the file.
The problem is that the returned value go_On is 1 instead of 10.
I think that the problem arises by the fact that I call the “send” function inside itself. In fact, if I put
return 10;
before the line
result = send(VOTE_COMMIT, 1);
go_On assumes the correct value 10.
Is the call of the “send” function inside itself the source of the problem? How can I solve it so that the returned value becomes 10?
Thanks to everybody who will help me.
You need to return the value from the recusive call.
If you send something else than
VOTE_REQUESTorVOTE_COMMITinto the function you should return an error value like-1: