Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!bionet!agate!ucbvax!hplabs!hpda!hpcuhb!swami From: swami@hpcuhb.HP.COM (V. Swaminathan) Newsgroups: comp.lang.c Subject: Question on function pointers Message-ID: <9580003@hpcuhb.HP.COM> Date: 22 Aug 89 18:58:29 GMT Organization: Hewlett Packard, Cupertino Lines: 33 When I was experimenting out with function pointers in C, I came up with this C code. I don't know how to cast the contents of a character pointer to function pointer ? Can this be done at all ? Logically it doesn't look possible for me. Can any netters enlighten on this ? ----------------------------------------------------------------------- #include char *prtmsg(); char *(*fnptr[])() = {prtmsg, prtmsg, NULL}; main() { char *(*fnptr1)(); char *msg="prtmsg"; int j; for(j=0; fnptr[j] != NULL; j++) printf("%s\n",fnptr[j]()); /* This works fine, as expected */ fnptr1=(char *(*)())msg; /* How do I cast this to function ptr? */ fnptr1(); /* Of course, there it is.. our familiar core dump !! */ } char *prtmsg() { char *rtn; rtn="First prtmsg"; return(rtn); }