goto/forth

Thomas M. Breuel tmb at talcott.UUCP
Fri Feb 22 12:38:55 AEST 1985


> Technically it is illegal to assign `a=b', altho some compilers allow 
> it. I read the release notes of a C compiler (pwb?) by dmr wondering
> why a label could be passed to as an argument. It seemed to be 
> interpreted as a funxion ptr. Try using setjmp/longjmp to do this.

setjmp/longjmp are slow, and they have the (in this case undesirable)
side effect of re-storing automatic variables. When I was faced with
the problem in a LISP interpreter, I came up with:

#define transfer(f)	return(fun)f

fun next();

fun start()
{
	transfer(next);
}

eval()
{
	register fun kont=start;

	while(kont) kont=(fun)(*kont)();
}

This is actually relatively fast and efficient (at least on a 68000).
The price that you pay is that certain things (in particular in a
LISP interpreter) become difficult because you can't really call eval
recursively. In my case that does not matter, since the LISP evaluation
stack is handled separately anyhow, and since I am using a non-recursive
garbage collector, a pushdown automaton for the reader, ... .

						Thomas.



More information about the Comp.lang.c mailing list