News for hackers. Stuff that matters.
Re:C for high level programmers (slides) by MarkSweep on Monday June 01, 2015 @01:30AM (#9636932)
That's not really the best example of using goto's, as that code is generated from this file:

https://github.com/zedshaw/mongrel2/blob/master/src/http11/h...

A nicer example of the use of goto's in Mongrel2 is the check macro:

https://github.com/zedshaw/mongrel2/blob/a884aef0f4a460e130d...

The convention of the project is that every function that has to deal with an error condition has an "error" label. These macro a used to jump to that label to clean up the function before returning. Here's an example:

https://github.com/zedshaw/mongrel2/blob/a884aef0f4a460e130d...

I think that this use of gotos is more clear than the alternative of a lot of nested if statements checking for success or having the clean up logic duplicated in a lot of places.

There are no comments on this comment yet.