Re:If goto statements are bad why does linux src have more t...
by kabdib on Tuesday December 16, 2014 @09:58PM
(#8760860)
Yeah, I've been on teams that have used this kind of error handling extensively, at several different companies. It's lightweight, very little is being done behind your back (do you know when your destructors are being called? really?) and it's easily inspected.
Also, never pass up the opportunity to troll a god-fearing "goto puritan" :-)
Zed Shaw introduces some debug macros here which make use of a goto:
http://c.learncodethehardway.org/book/ex20.html
From that point on in the book, pretty much every function written has an "error:" label at the bottom where stuff gets cleaned up and memory freed. You can see his example code for it there.
Pretty useful macros, really. Context for the "goto considered harmful" always seems lost on young coders these days, unaware of the kind of spaghetti code that overuse of goto had caused.