What happened to labels
COTTRELL, JAMES
cottrell at NBS-VMS.ARPA
Sat Mar 1 10:12:13 AEST 1986
/*
> 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: <code> break;
case 2: label2: <code> break;
...
case n: labeln: <code> 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 at nbs
*/
------
More information about the Comp.lang.c
mailing list