What's in a function pointer?
David Keppel
pardo at june.cs.washington.edu
Sat Nov 19 09:13:51 AEST 1988
I'm trying to write an interface specification for a set of routines
that should provide a machine-independent interface for runtime
generation of code.
One problem I'm having is in figuring out the "most general pointer
type". I have a routine that needs to return a pointer to a function,
but I don't know at the time that I compile the routine whether I
should be returning void(*)(), int(*)(), struct foo(*)(), or what.
I'm also having problems figuring out what data type the
pointer-into-code-space is supposed to be. Perhaps there isn't any
good type? What I need to do is something like:
void *data = flydatalloc (size);
???? *binary = flybinalloc (size);
struct zorch (*bork)(), retval;
read (fd, (char *)data, OBJ_FILE_SIZE);
/*
* Function exists in data space. Modify *in data space*
* so that it will be at the right address when it is copied
* into binary space.
*/
function_size = link (data, "glorf", binary);
copy_binary_from_data (binary, data, FUNCTION_OFFSET);
bork = (struct zorch (*)())
get_function_pointer (binary, FUNCITON_OFFSET);
retval = (* bork)();
free (data);
free (binary);
The routine "link" is going to need to use the "binary" pointer as the
start address of the object file *not* as the start address of the
function itself. Thus the "binary" pointer should *not* contain
entry-point control information (or at the least, "link" doesn't need
it). On the other hand, there's no guarantee that any data type other
than some most-general-function-pointer-type is big enough to hold the
pointer. Should I use a function pointer and assume that "link" will
be able to strip out any entry-point control information?
Sorry if this is phrased badly, but if I understood the issues I
probably wouldn't need to ask the question. aTdHvAaNnKcSe
;-D on ( Or was that Ham on Rye? Anyway... ) Pardo
--
pardo at cs.washington.edu
{rutgers,cornell,ucsd,ubc-cs,tektronix}!uw-beaver!june!pardo
More information about the Comp.std.c
mailing list