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!seismo!brl-adm!brl-smoke!smoke!cottrell@NBS-VMS.ARPA From: cottrell@NBS-VMS.ARPA (COTTRELL, JAMES) Newsgroups: net.lang.c Subject: What happened to labels Message-ID: <1420@brl-smoke.ARPA> Date: Fri, 28-Feb-86 19:12:13 EST Article-I.D.: brl-smok.1420 Posted: Fri Feb 28 19:12:13 1986 Date-Received: Mon, 3-Mar-86 00:35:55 EST Sender: news@brl-smoke.ARPA Lines: 50 /* > I recall that C on early UNIX's treated labels as constants of type > (int *). As a result, you could assign labels to variables and even > jump to the label in a variable. This got taken out of K&R, and > as I far as I can tell it's not in other C's today. > > This is unfortunate; I don't think you will get much sympathy on this point. > I ran into a situation recently in which I wanted > to (automatically) generate C code that should, for efficiency reasons, > contain label variables. I had to simulate them with a switch statement > of the form: > > switch(labelindex) { > case 1: goto label1; > case 2: goto label2; > ... > case n: goto labeln; > default: fprintf(stderr,"unknown label index: %d\n", > labelindex); > abort(); > } switch(labelindex) { case 1: label1: break; case 2: label2: break; ... case n: labeln: break; default: fprintf(stderr,"unknown label index: %d\n", labelindex); abort(); } > This is a lot slower, though, and some of the compiler's I tried it > on (the VAX VMS C compiler, for example) did not peephole optimize the > jump table implementing the switch and the branch instructions > implementing the goto's (this should have been treated as a jump > to a jump). > > I'm curious if any commerically available C compilers implement jumps > to arbitrary pointers without recourse to assembly language inserts. Probably not. I think they all wised up. Why don't you? jim cottrell@nbs */ ------