The compiler will always insert a RET
instruction at the end of a void
function (assuming it does not end by throwing an exception). An explicit return;
statement here is not needed, and will have no effect.
The generated assembly in your example is identical:
foo():
ret
bar():
ret
The explicit return
from a function is useful to exit the function early. For example:
void foo() {
// do some work ...
if (/* some condition */)
return;
// do more work ...
}
CLICK HERE to find out more related problems solutions.