3 ms·
Just putting the cleanup code in a separate function doesn't solve the problem. In C, goto can be used as a kind of fall-through mechanism to clean up all of t
by humbledrone 14y ago
Just putting the cleanup code in a separate function doesn't solve the problem. In C, goto can be used as a kind of fall-through mechanism to clean up all of the resources a function has acquired (but no more!), in the opposite order that they were acquired. There really is no other way to accomplish this without horrible if/else nesting, which for complex functions would be pretty ridiculous.
[1] http://eli.thegreenplace.net/2009/04/27/using-goto-for-error-handling-in-c/ http://eli.thegreenplace.net/2009/04/27/using-goto-for-error...