Arcane C hacks?

Guy Harris guy at sun.uucp
Sun Feb 23 21:41:32 AEST 1986


> >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 at sun.arpa	(yes, really)



More information about the Comp.lang.c mailing list