Arcane C hacks?

J.HARKINS jph at houxf.UUCP
Wed Feb 26 10:47:06 AEST 1986


> In articles <184 at bu-cs.UUCP> bu-cs!bzs (Barry Shein) writes:
> >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

Huh???

This line of code DOES NOT cast a char * into an int. It is declaring
that funtable is an array of MAXFNS elements, each of which is a pointer to 
a function that returns a int value.

> (not just a warning).  But in any case it is _not_ portable to the 3b2,

BOLDERDASH!!!

I have programs that use pointers to functions, some that run on 3B2/5's.
The construct is totally(no flames, please) portable.  As a matter of fact
I have used this type of construct to allow emulation of UN*X signal
processing on a non UN*X operating system that only allowed one routine
to be specified for all signals. 

> because all programs are pure -- you can't goto/call data space, nor
> can you read from the instruction stream.  Some sort of chastity belt
> in the hardware, I think.

Whazat??

MOST(not all) programs are pure in this environment, yes.  But that has
nothing to do with being able to use a pointer to a function.  The code
that is executed is actually in the shared text region; it is only the
pointer to the function that is in the data area.

-------
Disclaimer: I hereby disclaim all my debts.
------

Jack Harkins @ AT&T Bell Labs
Princeton Information
(201) 949-3618
(201) 561-3370
houxf!jph



More information about the Comp.lang.c mailing list