What happened to label variables?
Paul Dietz
dietz%slb-doll.csnet at CSNET-RELAY.ARPA
Sat Mar 1 09:06:51 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 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();
}
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.
More information about the Comp.lang.c
mailing list