goto/forth

cottrell at nbs-vms.ARPA cottrell at nbs-vms.ARPA
Thu Feb 21 03:29:40 AEST 1985


/*
> I came up with the following piece of C code the other night.  A friend and
> I were talking about ways of writing a generic Forth interpretor in C.
> We realized that the register save/restore at procedure call cost a lot
> when you have lots of small routines (as in a forth interpretor).  Also,
> a large switch statement has expenses of its own.  Then we thought about 
> indirect goto's.  et voila:
> 
> 	main()
> 	{
> 		int *a;
> 
> 	b:
> 		a = b;
> 		printf("a = 0x%x\n", a);
> 	}
> 
> (NOTE: This was compiled under 4.2BSD on a -750)
> 
> This compiles and runs perfectly.  However, when adding an obvious statement
> (namely, "goto *a") it won't let us compile it.  It seems like the compiler
> will *almost* let us do this.
> 
> What I want to know is, "can this be easily added to the language?",
> "Is it a reasonable thing to add?".  Comments anyone?
> 
> -- 
> -:--:-
> David Herron;

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.

	jim
*/



More information about the Comp.lang.c mailing list