Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!zephyr.ens.tek.com!tektronix!sequent!ccssrv!perry From: perry@ccssrv.UUCP (Perry Hutchison) Newsgroups: comp.lang.c Subject: Re: Pointers to functions on Xenix Message-ID: <616@ccssrv.UUCP> Date: 13 Sep 89 02:09:43 GMT References: <1989Sep8.021802.29203@Octopus.COM> Reply-To: perry@ccssrv.UUCP (Perry Hutchison) Organization: Control-C Software, Inc., Beaverton, OR Lines: 42 In article <1989Sep8.021802.29203@Octopus.COM> stever@octopus.UUCP (Steve Resnick) writes: > int echo(int, char **); /* The protos allow the forward refernce to */ > int setenv(int, char **); /* the functions */ > > struct ci /* This is the command table */ > { > char * name; /* The shell uses this name to compare > against the entered command */ > int (* fptr)(int, char **); /* and here is the function pointer */ > } Cmds[] = > "ECHO",echo, ^^^^ > "SET",setenv, ^^^^^^ > } ; ... > (Cmds[idx].fptr)(c,v); /* Here is where I call the function */ > > The error message is something like > > Term does not evaluate to a function. The type of member fptr is "pointer to a function", but the initial values given are "functions". Try preceding them with "&" thus "ECHO", &echo, ^ "SET", &setenv, ^ I would call it a bug that the compiler complained only about the call. It should have at least given a warning on the initialization. Also, in the call, you need to dereference the "pointer to function" in order to obtain a "function" which you can call, thus (* Cmds[idx].fptr)(c,v); /* Here is where I call the function */ ^