Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp Path: utzoo!linus!decvax!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.lang.c Subject: Re: Arcane C hacks? Message-ID: <3284@sun.uucp> Date: Sun, 23-Feb-86 06:41:32 EST Article-I.D.: sun.3284 Posted: Sun Feb 23 06:41:32 1986 Date-Received: Wed, 26-Feb-86 04:28:15 EST References: <184@bu-cs.UUCP> <592@bentley.UUCP> Organization: Sun Microsystems, Inc. Lines: 25 > >declare a table something like: int (*funtable[MAXFNS])() ; > >and just malloc the storage for the generated code. ... It should be > >quite portable (code generator aside) and is legal C. > > Well, some compilers will dislike the attempt to cast a (char *) into > a (int (*)()) ; in fact I think some will call it an outright error > (not just a warning). But in any case it is _not_ portable to the 3b2, > because all programs are pure -- you can't goto/call data space, nor > can you read from the instruction stream. 3B2, hell, that goes all the way back to separate I&D space on the PDP-11. It is quite unportable, and "lint" will justifiably complain about it, warning of a "questionable conversion of function pointer" (even if you're converting another kind of pointer *into* a function pointer, but that's life during UNIX). Then again, if they're generating code on the fly, it's not going to be very portable anyway, so if you're doing this sort of thing worrying about whether the pointer conversion is portable is kind of silly. (If you really MUST do this sort of thing, you can probably get the OS to help by providing a call to convert a data segment into a code segment.) -- Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.arpa (yes, really)