Typecast of Pointers to Functions

Bob Hearn hearn at claris.com
Wed Mar 29 09:37:39 AEST 1989


>From article <7689 at killer.Dallas.TX.US>, by brian at killer.Dallas.TX.US (Brian Pellerin):
> I am looking for an equivalent way to specify a typecast of a pointer to 
> a function other than using typedef.  For Example:
> 
>   typedef int (*FCN_PTR) ();
>   FCN_PTR     fcn_ptr1;
>   int         (*fcn_ptr2) (); 
> 
>   fcn_ptr1 = (FCN_PTR) NULL;  /* Typecast using typedef */
>   fcn_ptr2 = (???????) NULL;  /* Do Not Use the typedef.  What Goes Here? */
> 
> Any Suggestions?  Thanks.

What you want is:

fcn_ptr2 = (int (*)()) NULL;

The parens around the * are significant!  There is a simple way to to this
for any type: write a declaration, remove the identifier, and enclose it in
parens.  Thus:

int (*FCN_PTR)()    -->    int (*)()    -->   (int (*)())

Bob Hearn
hearn at claris.com



More information about the Comp.lang.c mailing list