Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!mit-eddie!genrad!decvax!decwrl!pyramid!prls!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: comp.lang.c Subject: Re: Function prototypes versus open() Message-ID: <817@mcgill-vision.UUCP> Date: Mon, 22-Jun-87 22:46:11 EDT Article-I.D.: mcgill-v.817 Posted: Mon Jun 22 22:46:11 1987 Date-Received: Sat, 27-Jun-87 04:47:36 EDT References: <18346@ucbvax.BERKELEY.EDU> <8042@utzoo.UUCP> <2210@hoptoad.uucp> <20538@sun.uucp> Organization: McGill University, Montreal Lines: 37 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.] > Trivial. Have the argument to the dispatcher, instead of being a > pointer to a function with a variable number of arguments, be a union > of a pointer to a function with three arguments, a pointer to a > function with four arguments, and a pointer to a function with five > arguments. Except that this makes it effectively impossible to use the dispatcher. Consider the call to the dispatcher that would have been written (under the old K&R paradigm) as int fxn(); ... dispatcher(....,fxn); How does on write the corresponding thing? (Please forgive any syntax errors, I don't have a copy of the draft - and won't until I can get one machine-readable!) 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. der Mouse (mouse@mcgill-vision.uucp)