How do I cast to "pointer to function returning int" ?

D. Richard Hipp drh at romeo.cs.duke.edu
Tue Apr 10 23:10:53 AEST 1990


In article <6090.2621f6c2 at csv.viccol.edu.au> timcc at csv.viccol.edu.au writes:
>struct foo {
>   char *name ;
>   int (*function) () ;
>   } ;
>
>struct foo foo_table[] = {
>   "bar",	(int * ()) bar,
>   "blurfl",	(int * ()) blurfl,
>   "frobjitz",	(int * ()) frobjitz,
>   } ;

The typecast (int *()) is for "function returning pointer to integer".
To get "pointer to function returning integer" use (int (*)()).

The rule is this: operators on the right hand side bind tighter than
operators on the left hand side.  Thus "()" binds tighter than "*".
You want the "*" to bind closest, so the extra parenthesis are required.



More information about the Comp.lang.c mailing list