Hacker News new | ask | show | jobs
by AdmiralAsshat 4209 days ago
They're usually used for an error clean-up section at the bottom.

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.

1 comments

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" :-)