4 ms·
I find that using goto for cleanups makes many functions much much clearer and I think it cuts bugs. Rather than writing the cleanup that is appropriate for ea
by t43562 5y ago
I find that using goto for cleanups makes many functions much much clearer and I think it cuts bugs.
Rather than writing the cleanup that is appropriate for each particular exit point you write one big cleanup at the end of the function that deals with everything.
It adds some potentially unnecessary if statements (to see if some pointer was allocated or not before trying to free it or to see if some file handle was opened before closing it). To me it has always seemed well worth it - shortening the code and greatly simplifying the chains of error-handling if statements.