Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!umd5!brl-adm!cmcl2!phri!manhat!mancol!marob!daveh From: daveh@marob.MASA.COM (Dave Hammond) Newsgroups: comp.lang.c Subject: Casting function ptrs Message-ID: <281@marob.MASA.COM> Date: 18 May 88 20:48:37 GMT Reply-To: daveh@marob.UUCP (Dave Hammond) Organization: 18th Street Construction Co NY NY Lines: 43 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 }; And a routine which is passed a function name in order to lookup and return its associated address: unsigned *lookup_func(name) char *name; { ... return( (unsigned *) f->func ); } How does one declare the lookup function, the return address variable and call the returned function, while properly casting the function return value? I'm doing it like so: unsigned *lookup_func(); unsigned *(*func)(); char *retp; if ((func = lookup_func("foo")) != (unsigned *)0) { if (( retp = (char *) (*func)() )) printf("retp=%s",retp); } Yes? No? Gonna blow up on me at some point ? Dave Hammond DSI Communications, Inc. -------------------------------- UUCP: ...!marob!daveh VOICE: (516)872-3535 USMAIL: 333 W. Merrick Rd. Valley Stream, NY 11580 --------------------------------