Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a reason for an empty return statement at the end of void function?

Tags:

c++

syntax

return

I was just looking at someone else's code and they have an empty return statement at the end of a void function:

void someFunction (int* someArg, int someArg2, int someArg3) {

    // some operations/function calls/recursion

    return;
}

Is there a particular reason why it should be there?

like image 759
Oleksiy Avatar asked Feb 15 '23 16:02

Oleksiy


1 Answers

There's no reason it needs to be there at the very end of a function, as far as I know. It's possible the function originally returned a value, someone changed it to a void, and just replaced return value; with return;. Or someone not very experienced with C++ assumed that every function must have a return, and will blindly believe this to the bitter end.

Now, a return in the middle of a function is definitely relevant since it stops the execution of the function at that point.

like image 162
maditya Avatar answered May 10 '23 04:05

maditya