case stmt != jumptable of goto labels !!!!!!!!!

John Gilmore gnu at hoptoad.uucp
Tue Feb 25 13:37:44 AEST 1986


It is true that a case (in C, "switch") statement is not the same
as a jump vector, because the vector cannot be modified.  However,
a trivial hack gives the behaviour you want:

	int vector[MAX_JUMPS];

	switch (vector[i]) {

This costs one subscripting operation per jump -- a price, but a small price.
Not nearly the overhead of a function call, for example.  I've seen exactly
this kind of contruct used for the inner loop of an interpreter.  It
probably works OK for a regular expression scanner, or lexer, too.

You can even do it one better by declaring

	int *vector;

and pointing it at whatever jump table you are currently interested in,
out of a set of precompiled or dynamically built jump tables.

Are we having done yet?
-- 
John Gilmore  {sun,ptsfa,lll-crg,ihnp4}!hoptoad!gnu   jgilmore at lll-crg.arpa



More information about the Comp.lang.c mailing list