Article View: comp.std.c
Article #5431What's in a function pointer?
From: David Keppel
Date: Fri, 18 Nov 1988 23:13
Date: Fri, 18 Nov 1988 23:13
48 lines
2470 bytes
2470 bytes
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@cs.washington.edu
{rutgers,cornell,ucsd,ubc-cs,tektronix}!uw-beaver!june!pardo
Technical Details
Message-ID:
<6465@june.cs.washington.edu>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!husc6!mailrus!cornell!uw-beaver!uw-june!pardoShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!husc6!mailrus!cornell!uw-beaver!uw-june!pardo From: pardo@june.cs.washington.edu (David Keppel) Newsgroups: comp.std.c Subject: What's in a function pointer? Summary: I need an address, I think. Message-ID: <6465@june.cs.washington.edu> Date: 18 Nov 88 23:13:51 GMT Reply-To: pardo@cs.washington.edu (David Keppel) Organization: U of Washington, Computer Science, Seattle Lines: 48