Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!uunet!lupine!rfg From: rfg@NCD.COM (Ron Guilmette) Newsgroups: comp.std.c Subject: Re: prototypes required ? Keywords: printf stdargs prototypes Message-ID: <2150@lupine.NCD.COM> Date: 19 Oct 90 01:25:00 GMT References: <4026@otis.oakhill.UUCP> <14164@smoke.BRL.MIL> Organization: Network Computing Devices, Inc., Mt. View, CA Lines: 58 In article <14164@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes: >In article <4026@otis.oakhill.UUCP> jeff@oakhill.UUCP (Jeff Enderwick) writes: >>Is it legal for a compilation system to require prototypes when stdarg >>functions are used ? It valid for the compiler to require you to include >>the prototype: >> int printf ( const char*, ... ); >>before making the call: >> printf ( "hello %d worlds\n", 5 ); > >Yes, you definitely must have a prototype in scope before calling a >variable-argument function in a strictly conforming program. > >For printf(), you should #include instead of declaring it >yourself. You might get better results that way in some implementations. Along the same lines, I also have a related question. Now please excuse my almost total ignorance regarding the x3j11 requirements regarding the contents of include files, but I don't immediately see where (in 4.9.1) it says (explicitly) what function are required to be declared within . Are all of the function listed in 4.9.4 thru 4.9.10 required to have declarations within ? If so, are they required to have prototyped declarations? Non-prototyped? Either? Part of the reason that I ask is that I was doing some work recently on a machine for which the va_list type is a structure, and I encountered an odd problem. I was porting some code to this machine, and I got an error on a hunk of code like: #include ... ... va_list args; ... vfprintf (file, fmt, args); /* <= error here */ as it turned out, the creators of the file in question had cheated and put a declaration like the following in it: int vfprintf (FILE *, const char *, void *); Obviously, that last formal parameter type is not correct! That's why I got an error at the call. I tried changing the last formal type to (a more correct) `va_list', but when I did that this changed the file into something that could *not* be included ALL BY ITSELF into *any* given file. Rather, it now always had to be preceeded by a #include . So what it the `correct' thing to have in the file regarding the vfprintf function (and friends)? -- // Ron Guilmette - C++ Entomologist // Internet: rfg@ncd.com uucp: ...uunet!lupine!rfg // Motto: If it sticks, force it. If it breaks, it needed replacing anyway.