3 ms·
I agree, having a single return point makes debugging that much easier. Back at Microsoft, the following pattern was used quite extensively in the OS group:
by xfax 13y ago
I agree, having a single return point makes debugging that much easier.
Back at Microsoft, the following pattern was used quite extensively in the OS group:
int someFunc() {
DWORD error = ERROR_SUCCESS;
error = foo();
if (error != ERROR_SUCCESS) {
goto Clean0;
}
error = bar();
if (error != ERROR_SUCCESS) {
goto Clean0;
}
....
Clean0:
return error;
}
- philsnow 13y agoThis style is used in the linux kernel as well; there can be multiple resources acquired that sometimes need to be released in reverse order, so there are often multiple labels that you can goto, depending on how much stuff you have to unwind before you return.