int abc(void *ctx) { int rc = -1;
if (outcome_of_first() != SUCCESS) {
my_log(MY_LEVEL, "Log my error");
goto over;
}
if (outcome_of_second() != SUCCESS) {
my_log(MY_LEVEL, "Log my error");
goto over;
}
...
rc = 0;
over:
if (something_allocated != NULL)
free(something_allocated); if (something_else_allocated != NULL)
free(something_else_allocated);
return rc;
}Not as performant, no. But the complaint about GOTO is that it tends to be a hallmark of less-maintainable code. This example falls right in with that complaint on account of being a less-maintainable way to write code.
When writing software manually, this is rarely the best choice, but for automatic generation of code, this is very powerful.
Do never listen to the stupidities that are said to sell code quality checking software.