Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: Notesfiles $Revision: 1.6.2.14 $; site umn-cs.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!stolaf!umn-cs!herndon From: herndon@umn-cs.UUCP Newsgroups: net.lang.c Subject: Arcane C hacks? Message-ID: <1700003@umn-cs.UUCP> Date: Mon, 17-Feb-86 23:44:00 EST Article-I.D.: umn-cs.1700003 Posted: Mon Feb 17 23:44:00 1986 Date-Received: Wed, 19-Feb-86 03:49:12 EST Lines: 35 Nf-ID: #N:umn-cs:1700003:000:1667 Nf-From: umn-cs!herndon Feb 17 22:44:00 1986 I wrote a mild flame in another newsgroup about this, but somebody out there might know another way. The problem is this: I'd like to construct a jump table by putting lots of labels into an array, and then issuing a statement like goto jumptab[i]; Unfortunately, labels are no longer simple integers (and haven't been for most of a decade now). They can no longer be type coerced to integer or pointer-to-integer, nor can other types be coerced to type label. Is there any way around this? Admittedly, for the static case with a dense list, a switch statement usually constructs a jump table, but I'd like to construct one on the fly. If I just want to execute machine code out of an array ("goto array_name;" used to be legal C) I can write a simple assembly language routine of one argument to do it. Is there a legal way to do this in pure C any more? (Yes, one can type coerce the address of the array to pointer-to-function and call it, but is it possible to jump to the array?) Both of these problems are admittedly things one would not often do. They are, however, things one might do in an interpreter. The former operation may be considered to be "machine independent", as there is one reasonable, consistent interpretation. The latter is much more open to question, as the contents of the array are not machine independent. However, if one is to write portable inter- preters, being able to jump to an array without assembly language help would be a plus. (Individual pseudo-machine operations can then be relegated to data tables, leaving the C code machine independent.) Robert Herndon ...!{ihnp4|stolaf}!umn-cs!herndon