Casting function ptrs

Dave Jones djones at megatest.UUCP
Fri May 20 08:21:11 AEST 1988


in article <281 at marob.MASA.COM>, daveh at marob.MASA.COM (Dave Hammond) says:
> 
> 
> Given a list of varying typed functions, their names and addresses:
> 
> struct funcs {
>     char *name;
>     unsigned (*func)();
> }
> char *foo();
> struct funcs f = {  "foo", (char *)foo };

...

typedef unsigned (*func_ptr)();

struct funcs {
  char* name;
  func_ptr func;
} func_table;

func_ptr
func_lookup()
{ ... whatever ... }

{
  func_ptr proc;
  char* func_name = ... whatever ...;
  unsigned result;

  if((proc = func_lookup(func_name)) != (func_ptr)0)
	result = (*proc)();
  else
	fprintf(stderr, "Shucks.\n");
}



More information about the Comp.lang.c mailing list