Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!vrdxhq!bms-at!stuart From: stuart@bms-at.UUCP (Stuart D. Gathman) Newsgroups: comp.lang.c Subject: Re: Function prototypes versus open() Message-ID: <409@bms-at.UUCP> Date: Mon, 29-Jun-87 18:39:07 EDT Article-I.D.: bms-at.409 Posted: Mon Jun 29 18:39:07 1987 Date-Received: Wed, 1-Jul-87 01:55:23 EDT References: <18346@ucbvax.BERKELEY.EDU> <8042@utzoo.UUCP> <2210@hoptoad.uucp> <817@mcgill-vision.UUCP> Organization: Business Management Systems, Inc., Fairfax, VA Lines: 56 Summary: How about this: 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: > > Trivial. Have the argument to the dispatcher, instead of being a > > pointer to a function with a variable number of arguments, be a union . . . > 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 > int fxn(int x; int y; double z); > ... > dispatcher(....,fxn); *** Solution A typedef union { int (*type3)(int,int,double); int (*type4)(int,int,double,double); } disp_fxn; ... dispatcher(....,(disp_fxn)fxn); I know, this is not allowed, but I wish it was! Perhaps it should be: dispatcher(....,((disp_fxn)fxn).type3); or dispatcher(....,(disp_fxn.type3)fxn); Would this be portable? Uglier, but I know it would work is: *** Solution B { disp_fxn temp; dispatcher(....,temp.type3=fxn); } We use indirect functions all over the place. We not been using function prototypes since some of the compilers we support don't have them. As a result, there are many bugs resulting from the wrong parm type being passed to a function called through a table. It would be nice to have a way to lint indirect function calls without the mess of 'B'. Worse yet, are dynamic indirect function calls. This is where the function pointers are themselves stored in a table! This is impossible to lint, since lint cannot guarrantee what kind of pointer will actually reside in a function pointer variable at run time. At this point, I start leaning towards O-O! -- Stuart D. Gathman <..!seismo!dgis!bms-at!stuart>