Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!cit-vax!elroy!jplgodo!wlbr!scgvaxd!stb!michael From: michael@stb.UUCP Newsgroups: comp.lang.c Subject: Re: Function prototypes versus open() Message-ID: <1569@stb.UUCP> Date: Fri, 5-Jun-87 00:51:42 EDT Article-I.D.: stb.1569 Posted: Fri Jun 5 00:51:42 1987 Date-Received: Sun, 7-Jun-87 01:04:47 EDT References: <18346@ucbvax.BERKELEY.EDU> <8042@utzoo.UUCP> <2210@hoptoad.uucp> <931@wjvax.wjvax.UUCP> <20119@sun.uucp> Reply-To: michael@stb.UUCP (Michael) Organization: STB BBS, La, Ca, USA, 90402, 213-459-7231 Lines: 66 In article <20119@sun.uucp> guy%gorodish@Sun.COM (Guy Harris) writes: >> How about functions called with function pointers? I am not that familiar >> with the details of function prototyping in the standard, but will it be >> possible to invoke functions with variable arguments with function pointers? > >From the October 1, 1986 draft: > > 3.5.3.3 Function declarators (including prototypes) > > ... > > Here are two more intricate examples: > > int (*apfi[3])(int *x, int *y); > > declares an array "apfi" of three pointers to functions returning > "int". Each of these functions has two parameters that are > pointers to "int".... > >which implies that the type of a function pointer, just like the type >of a function, includes the types of its arguments as well as the >type of its result. As such, you can declare > > int (*pintvarargs)(int i, ...); > >which is a pointer to a function whose first argument is an "int" and >which may have 0 or more optional arguments after that. A function >pointed to by "pintvarargs" can be called with a variable-length list >of arguments, as long as that list has at least one argument and the >first argument is of a type that can be coerced to "int". The >declaration > > int (*pintarg)(int i); > >declares a pointer to a function whose *only* argument is an "int". >A function pointed to by "pintarg" may only be called with one >argument, which must be of a type that can be coerced to "int". > >The deprecated old-style declaration > > int (*pwhoknows)(); > >is, I infer, equivalent to > > int (*pwhoknows)(...); > >which declares a pointer to a function which may have 0 or more >optional arguments. > Guy Harris > {ihnp4, decvax, seismo, decwrl, ...}!sun!guy > guy@sun.com Wait a sec. Would you please explain how the following can be done: I have a dispatcher routine, that takes a pointer to a function, some args, does some munching on the args, and calls the pointed to routine with 3, 4, or 5 args. Each routine called is expecting a known, fixed # of args, yet the pointer used is with variable args. So, according to the above, I have to declare the function pointer as variable args, which activates one calling convention, yet the routines are fixed args, and expecting another calling convention. -- : Michael Gersten seismo!scgvaxd!stb!michael : The above is the result of being educated at a school that discriminates : against roosters.