Pointers to functions on Xenix

Perry Hutchison perry at ccssrv.UUCP
Wed Sep 13 12:09:43 AEST 1989


In article <1989Sep8.021802.29203 at Octopus.COM> stever at 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 */
     ^



More information about the Comp.lang.c mailing list