Arcane C hacks?
Jeff Bowles
bowles at cbosgd.UUCP
Wed Feb 19 13:42:08 AEST 1986
(Gee, wasn't the article I'm replying to supposed to be here, too?)
Well, anyway, the article I'm following up is one where a programmer
asks why:
int i;
...
goto labels[i]; /* "levels" contains pointers to, well,
* you get it...
*/
went away from C. [I guess it used to be valid. Hmmmm.]
If you feel the need to do something like this, you probably want
to just use a structure:
struct bletch {
int l_token; /* If you see this, */
void (*l_whither)(); /* then call this routine */
};
Then you can just do a table lookup, calling the appropriate
routines for each item.
Or, :-), you can use the "computed goto" that C provides:
switch (i) {
case 0:
...
break;
case 1:
...
}
The "table lookup" that C provides will usually do what you
need, with minimal effort. If you're translating an assembler
program and need to "jump to the location specified by the N'th
element of this array", I suggest finding a BCPL compiler.
Jeff Bowles
Lisle, IL
More information about the Comp.lang.c
mailing list