Path: utzoo!mnetor!uunet!yale!husc6!cca!g-rh From: g-rh@cca.CCA.COM (Richard Harter) Newsgroups: comp.lang.c Subject: Re: Put your code... (was Re: gotos Message-ID: <27389@cca.CCA.COM> Date: 26 Apr 88 16:12:25 GMT References: <2597@ttrdc.UUCP> <165600045@uiucdcsb> Reply-To: g-rh@CCA.CCA.COM.UUCP (Richard Harter) Organization: Computer Corp. of America, Cambridge, MA Lines: 48 In article <165600045@uiucdcsb> kenny@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.