Comment Re:why? (Score 1) 677
There is a time and place to use goto. It works well for handling error cases and can lead to better code.
Instead of:
rc = some_function()
if (rc) {
do lots of cleanup of earlier stuff()
return rc;
}
rc = some_other_function()
if (rc) {
do even more cleanup()
return rc;
}
I can just use:
rc = some_function();
if (rc)
goto error_handler;
error_handler:
perform any needed cleanup
return rc;
}
The other method would be a huge nested mess of if/else conditions.