vic@zen.UUCP (Victor Gavin) (01/28/89)
I have recently had a problem in using ANSI C prototypes and vararg functions. The function I was creating required two obligatory parameters and the rest were optional. The function was declared void foo(va_alist) My problem was that to catch any mistakes in programs which call it I used the prototype extern void foo(int,int,...); This prototype is included by the file that contains the function and so the compiler keeps complaining about type mis-matches on parameter one. I can understand this but I'd like to know if there is some way of explaining to the compiler (MS C v5.1, warnings level 3) that I don't want an error message coz the code is kosher. My other problem is that there isn't a varargs version of scanf(). Is there one in ANSI C or is it something that only I would find useful? vic -- Victor Gavin Zengrange Limited vic@zen.co.uk Greenfield Road ..!mcvax!ukc!zen.co.uk!vic Leeds LS9 8DB +44 532 489048 England
gwyn@smoke.BRL.MIL (Doug Gwyn ) (02/02/89)
In article <1494@zen.UUCP> vic@zen.UUCP (Victor Gavin) writes: >The function I was creating required two obligatory parameters and the rest >were optional. The function was declared > void foo(va_alist) I think you mean that was the declaration used in the function definition? That's not ANSI C in any case. For ANSI C you must use the ",..." form of declaration/definition for varargs functions. va_alist belongs to the old <varargs.h>, not ANSI C and <stdarg.h>. >My problem was that to catch any mistakes in programs which call it I used >the prototype > extern void foo(int,int,...); That's okay. Fix the function definition to have the same shape. >My other problem is that there isn't a varargs version of scanf(). Is there >one in ANSI C or is it something that only I would find useful? No, v*scanf() are not in the proposed ANSI C Standard. In fact there was considerable sentiment for removing the normal *scanf() functions. I'm not sure how useful v*scanf() would be; I've never felt the need for it, though.
vu0112@bingvaxu.cc.binghamton.edu (Cliff Joslyn) (02/03/89)
In article <9553@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes: >No, v*scanf() are not in the proposed ANSI C Standard. In fact there >was considerable sentiment for removing the normal *scanf() functions. > >I'm not sure how useful v*scanf() would be; I've never felt the need >for it, though. In Turbo C v2.0, *scanf() appears to fail for a few arguments (>3?), but the v*scanf() functions provided work much better for me. Food for mailer Food for mailer Food for mailer -- O----------------------------------------------------------------------> | Cliff Joslyn, Cybernetician at Large | Systems Science, SUNY Binghamton, vu0112@bingvaxu.cc.binghamton.edu V All the world is biscuit shaped. . .
guy@auspex.UUCP (Guy Harris) (02/04/89)
>>I'm not sure how useful v*scanf() would be; I've never felt the need >>for it, though. > >In Turbo C v2.0, *scanf() appears to fail for a few arguments (>3?), but >the v*scanf() functions provided work much better for me. The term generally used in descriptions of this situation, assuming you used "*scanf" properly, is "bug"; bugs in Turbo C v2.0 aren't relevant to the question of whether either "*scanf" or "v*scanf" are useful enough to be included in the ANSI C standard.
jeenglis@nunki.usc.edu (Joe English) (02/06/89)
gwyn@brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes: >In article <1494@zen.UUCP> vic@zen.UUCP (Victor Gavin) writes: [...] >>My other problem is that there isn't a varargs version of scanf(). Is there >>one in ANSI C or is it something that only I would find useful? > >No, v*scanf() are not in the proposed ANSI C Standard. In fact there >was considerable sentiment for removing the normal *scanf() functions. > >I'm not sure how useful v*scanf() would be; I've never felt the need >for it, though. Are v?printf also not in the standard? I've used vsprintf a couple of times (on the apparently mistaken assumption that it would be portable across compilers). It's proven useful when I wanted to use printf-style output with a non-file output object. (For example, in a window package for IBM PCs). Is there a way to do the following in ANSI-conformant C: void winprintf(struct WINDOW *w,char *fmt,...) { va_list ap; char buffer[BIGNUMBER]; va_start(ap,fmt); vsprintf(buffer,fmt,ap); va_end(ap); winputstring(w,buffer); } --Joe English jeenglis@nunki.usc.edu
gwyn@smoke.BRL.MIL (Doug Gwyn ) (02/07/89)
In article <2607@nunki.usc.edu> jeenglis@nunki.usc.edu (Joe English) writes: >Are v?printf also not in the standard? Yes, v*printf() are in the proposed ANSI C standard. They have proven utility. You should be aware that 4.2BSD did not supply them.