I see functions/methods with a void return in the signature that have a return statement at the end of the function. What is the reason for this, and does this apply to other languages?
For all I know, I can use return if I want to exit anywhere else but the end of the function.
A C example:
void function(void)
{
int x = 1 + 2;
return; // what do we need this for, if at all?
}
This seems pointless here. But my guess is that this kind of thing can be used to put a breakpoint in IDEs which don't support putting a breakpoint at the closing brace and by putting a breakpoint here, some values can be checked in the watch window etc.
Someone took a 'a function must have a single return' coding guideline too literally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With