Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!cmcl2!seismo!brl-sem!brl-smoke!smoke!dmh@mit-borax.ARPA From: dmh@mit-borax.ARPA (David Harmon) Newsgroups: net.lang.c Subject: goto jumps into loops Message-ID: <69@brl-smoke.ARPA> Date: Wed, 16-Apr-86 20:24:06 EST Article-I.D.: brl-smok.69 Posted: Wed Apr 16 20:24:06 1986 Date-Received: Fri, 18-Apr-86 20:59:58 EST Sender: news@brl-smoke.ARPA Lines: 78 Nice timing...Steve Summit's letter about jumping into blocks arrived just as I had finished debugging a routine which I actually wrote in Pascal and just translated into C for practice. You guessed it, it jumps into a loop, and I honestly don't think there is a way to avoid the goto without some VERY ugly code to keep track of the program's state. The problem is that I need to print out all the elements of a set capable of containing or not containing any value from 0..255. (In Pascal, a SET OF 0.255) That in itself would be no problem given the IN operator, but I also wanted to contract adjacent members of a set into a range syntax. Assume that the include file "nastydefs" contains the definitions of the set type and in() function. Can any of you figure out a way to do this elegantly without the goto? Especially this may involve the break or continue statements...I have looked at possibilities but I must admit I probably don't know a lot of tactics involving them. Also, with an appropriate include file, this procedure both compiles and passes lint. Dave Harmon dmh@mit-borax.arpa dmh@borax.lcs.mit.edu /* Assume the existence of a type named "set", which is intended to simulate the Pascal TYPE KeySet:SET OF 0..255; Further assume the existence of a function in(e,l); set *l; char e; which returns a boolean 1 iff _e_ is an element of _*l_. */ #include #include "/usr/dmh/nastydefs" wrtlist (listp) set *listp; /*This routine should print out a list of the members of List, with adjacent members shown contracted as N-M, where N and M are the bounds of a range of members. Notice the GOTO statement which gives the effect of two *crossed* loops with a Write and a conditional increment shared by both. Note that the potential member 0 is not used by the application. */ #define MAX NUM_KEYWORDS /*The highest element in use by the application*/ { unsigned char i; set list; i=0; list= *listp; do { putchar(' '); do { if (i=MAX) return(0); else i++; } while (in(i,&list)); cross: /*Beginning of GOTO Loop and shared section*/ printf("%d",i); if (i=MAX) return(0); else i++; } while (in(i,&list)); putchar('-'); while ( (i