Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mit-athena.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!bellcore!decvax!mit-athena!jc From: jc@mit-athena.ARPA (John Chambers) Newsgroups: net.lang.c Subject: Re: goto's in 'C' Message-ID: <50@mit-athena.ARPA> Date: Fri, 25-Jan-85 09:37:43 EST Article-I.D.: mit-athe.50 Posted: Fri Jan 25 09:37:43 1985 Date-Received: Mon, 28-Jan-85 06:35:13 EST References: <308@harvard.ARPA>, <137@redwood.UUCP> Organization: MIT, Project Athena, Cambridge, Ma. Lines: 34 > The incidence of the "goto" in C code is so rare anyway, I dare say > we could abolish it altogether (replacing it with BLISS's "leave") > and not miss the loss. Don't you dare! There are some of us who need to write "pre-processors" to translate some funny (usually special-purpose) language into something compilable. C is a popular target for such translators. The main reason is that C's grammar is flexible enough that it's relatively easy to generate it. Without gotos, it would be much harder. Have you ever tried to write a routine to generate properly structured code when the semantics of the languages don't quite line up? The only practical way I know of is with labels and gotos. Granted, gotos may be undesirable with human-generated code. I use them, but normally only to exit from deep nesting, and even this can be done with only a small loss of performance by writing subroutines and using return instead of goto. But generating structured code automatically? Does anyone know a clean way to do this? If you want a test case to play with, consider translating a C for loop into the goto-less language of your choice. Take an example like: for (i=0,p=&x[j]; *p && p->f && p->f[i]; i++, p=p->next) { ... if (p->x >= p->f[i]) break; ... } Note that I'm not asking how you would express this in your goto-less language. That's easy. I'm asking how you would write a translator that takes this and produces code that is semantically exactly the same in your goto-less language. I contend that, with gotos it is in general easy; without gotos it is in general difficult. John Chambers