home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pmafire!news.dell.com!swrinde!sdd.hp.com!uakari.primate.wisc.edu!aplcen.apl.jhu.edu!anagld!sammy
- From: sammy@anagld.analytics.com (Sam Blackburn)
- Newsgroups: comp.lang.c
- Subject: Re: function pointers
- Message-ID: <1596@anagld.analytics.com>
- Date: 23 Aug 92 13:52:31 GMT
- References: <22AUG199219163464@mary.fordham.edu>
- Organization: Computer Sciences Corporation - Systems Engineering Division
- Lines: 30
-
- sbhatia@mary.fordham.edu (SABU) writes:
-
-
- >if(func == NULL)
- >..
- >else
- >..
- >In essence I want to either pass a function or a null pointer to indicate
- >an alternate processing approach.
-
- Sure, a pointer is a pointer is a pointer. My suggestion would be to
- typedef your function and then cast NULL to prevent any compiler warnings.
-
- typedef int (*MYFUNC)( int, int ); // MYFUNC is a pointer to a function that
- // accepts two ints and returns an int
-
- compute( x, function )
- int x;
- MYFUNC function;
- {
- if ( function == (MYFUNC) NULL )
- {
- return( x );
- }
-
- return( (*function)( x, 14 ) );
- }
-
- Some compilers allow you to call function( x, 14 ) directly while others
- require you to dereference the pointer first.
-