pardo@june.cs.washington.edu (David Keppel) (07/16/88)
Assume for the moment that I have a compiler that takes
prototypes, and knows about void* and all that jazz.
I want to write a function that can return pointers to
semi-arbitrary functions. I want to do something like:
(Can you say "run-time linker"? I *knew* you could!)
typedef void (*a_type)();
tyepdef int (*b_type)(int a, char *b[]);
typedef struct splat (*c_type)( struct splat a, char *s);
void *func_returning_func( int );
struct splat bork = {...};
:
void *ptr
:
ptr = func_returning_func( tag );
switch( tag ) {
case 1:
(*(a_type)ptr)();
break;
case 2:
s = (*(b_type)ptr)(2, "2");
break;
case 3:
bork = (*(c_type)ptr)( bork, "3" );
}
:
Given that "bork" is initialized properly, will this all
work? Portably? Even on machines that pass parameters in
registers unless (like bork) it is too big to fit in a
single register?
If this is broke, how can I do what I want?
E-mail, please.
;-D on ( Ok, now how about this: ) Pardo
pardo@cs.washington.edu
{rutgers,cornell,ucsd,ubc-cs,tektronix}!uw-beaver!june!pardo