Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcnc!rti!sas!bts From: bts@sas.UUCP (Brian T. Schellenberger) Newsgroups: comp.lang.c Subject: Re: Function prototypes versus open() Message-ID: <170@sas.UUCP> Date: Sun, 5-Jul-87 00:53:50 EDT Article-I.D.: sas.170 Posted: Sun Jul 5 00:53:50 1987 Date-Received: Sun, 5-Jul-87 21:22:18 EDT References: <18346@ucbvax.BERKELEY.EDU> <8042@utzoo.UUCP> <2210@hoptoad.uucp> <817@mcgill-vision.UUCP> Organization: SAS Institute Inc.,Cary NC,25712 Lines: 32 Summary: use a cast In article <817@mcgill-vision.UUCP>, mouse@mcgill-vision.UUCP (der Mouse) writes: > In article <20538@sun.uucp>, guy%gorodish@Sun.COM (Guy Harris) writes: > >> Wait a sec. Would you please explain how the following can be done: > >> [dispatcher which calls a fxn passed by a pointer as an argument, > >> with 3, 4, or 5 args. Each fxn expects known arg pattern.] > >> int fxn(int x; int y; double z); > ... > dispatcher(....,fxn); > > Oops. The argument to the dispatcher is not of type > int (*)(int,int,double) > but of type > union{int(*)(int,int,double);int(*)(int,int,double,double);} > instead. Ugly. Why not just use typedefs and casts to good effect; eg, typedef union{ int (*)(int,int,double); int (*)(int,int,double,double) } dispatch_fptr; dispatcher( ...., (dispatch_fptr)fxn ); A thousand forgivenesses if I am mistaken and ANSI in fact prohibits the obvious (I should wait 'til Monday to post this, so I can check my copy of the standard to be sure, but . . .). A cast seems the obvious solution. I *would* suggest that if ANSI disallows this, it should be fixed. --Brian. ...!rti!mcnc!sas!bts