prototypes required ?
Ron Guilmette
rfg at NCD.COM
Fri Oct 19 11:25:00 AEST 1990
In article <14164 at smoke.BRL.MIL> gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
>In article <4026 at otis.oakhill.UUCP> jeff at 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 <stdio.h> 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 <stdio.h>. Are all of the function listed in 4.9.4 thru 4.9.10
required to have declarations within <stdio.h>? 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 <stdio.h>
...
...
va_list args;
...
vfprintf (file, fmt, args); /* <= error here */
as it turned out, the creators of the <stdio.h> 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 <stdio.h> 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 <stdarg.h>.
So what it the `correct' thing to have in the <stdio.h> file regarding the
vfprintf function (and friends)?
--
// Ron Guilmette - C++ Entomologist
// Internet: rfg at ncd.com uucp: ...uunet!lupine!rfg
// Motto: If it sticks, force it. If it breaks, it needed replacing anyway.
More information about the Comp.std.c
mailing list