Subject: Re: release time?

Re: release time?

From: Peter Stuge <>
Date: Thu, 21 Jan 2010 21:22:13 +0100

Alexander Lamaison wrote:
> > Would anyone veto changes that reduce mindless code duplication such
> > as above with the use of forward gotos to the end of functions?
> Rather than gotos, how about a helper function e.g.:

A function brings a new scope which may not always work. goto is not
a bad thing if used right. I think forward gotos for error handling
is an excellent way to keep code clean, coherent and short:

main() {
  int ret=1;
  char *ptr=NULL;
    goto done;
  if(NULL==ptr) {
    goto done;

  /* main stuff */

  return ret;

> Or am I missing the need for gotos (not got the code in front of me)?

Cleaning up ptr in the above example is the point. Instead of
duplicating cleanup code in every single error handling branch within
main stuff, all cleanup code is in one single location.

That way, there is much less code overall and writing error handling
is greatly simplified, which means more likely to be done and much
more likely to not introduce new bugs because of overlooked cleanup.

Received on 2010-01-21