News for hackers. Stuff that matters.
Re:Linux Coding Style Guide: GOTOs not always considered har... by mrj on Tuesday August 23, 2011 @02:05PM (#2917598)
In C with it's lack of exceptions, goto can be used to jump unconditionally to cleanup code before exiting a function. This is far cleaner than every branch and loop following a call needing explicit instructions to check for error statuses, sometimes multiple errors (like malloc something, check for error, use dynamic memory in a call, check for a different error).

It's also more maintainable, since the error checking is done in a single place and a single jump. Without a goto, if there were a new error condition to check, it might take several updates to ensure all error conditions are accurately checked.

Generally, gotos for handling exceptional cases inside a function: okay. Goto for implementing twisted logic: bad.

There are no comments on this comment yet.