Put your code... (was Re: gotos

Richard Harter g-rh at cca.CCA.COM
Wed Apr 27 02:12:25 AEST 1988


In article <165600045 at uiucdcsb> kenny at uiucdcsb.cs.uiuc.edu writes:
>
>In short, use of _goto_ directly by a programmer is most likely
>excusable only where the _goto_ represents a panic exit condition.
>There are a few other cases where compilers and preprocessors can
>generate _goto_s freely.  All other uses are to be disparaged.

	This is from a very nice series of articles.  Well done, sir!

	In civilized languages I average about one goto per 15,000
lines of code, usually of the 'panic exit' form.  However the most
common instance is of the form

	procedure () {
		prolog code
		main body
epilog:		epilog code
		}

The gotos live in the main body at various levels of nesting and all
transfer to the epilog code which typicaly does things like returning
space to the allocator.  This, I suppose comes under the category of
multiple exits from a main body.  Sometimes you can arrange things to
use break statements -- sometimes this is not convenient.

In D or some other such language of the future one might find it profitable
to have an escape statement that takes you up to the top level within
the function, e.g.

	foobar () {
	   while (foo) {
	      stuff;
	      while (bar) {
	         more stuff;
                 if (stop_this_nonsense) superbreak;
                 other stuff;
                 }
               }
	    cleanup code;
	    }

Superbreak escapes all the way to the code following the outermost while,
i.e. the cleanup code.  
-- 

In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
	Richard Harter, SMDS  Inc.



More information about the Comp.lang.c mailing list