Arcane C hacks?

VLD/VMB gwyn at BRL.ARPA
Mon Mar 3 13:05:03 AEST 1986


I can think of two legal ways to implement the
	goto jumptab[i];
idea in C, assuming you need the flexibility of reassigning
the destinations for each i:

(1)  Use an array of jmpbufs, do something to get them initialized
using setjmp (that's the hard part), and longjmp to the correct
jmpbuf array member.

(2)  Use an array of function pointers, initialize them as desired,
and call via the appropriate function array member (watch out that
you don't keep recursing deeper and deeper; it's probably best to
have a common return from the functions).

I suspect that if we knew your intended application, better
solutions would be possible.  Just what do you think you need
a jump table for?



More information about the Comp.lang.c mailing list