prototypes required ?

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Oct 20 01:09:27 AEST 1990


In article <2150 at lupine.NCD.COM> rfg at NCD.COM (Ron Guilmette) writes:
>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?

Section 4.1.2.1 says: "Each header declares or defines all identifiers
listed in its associated section, ..."  While it does not explicitly
require that prototypes be used, a strictly conforming program must
assume that the standard headers might use prototypes.  Otherwise, it
would be depending on undefined behavior.

Of course it is expected that high-quality implementations WOULD use
prototypes in the standard headers, because that would produce better
diagnostic capabilities due to being able to check argument types.

>... put a declaration like the following in it:
>	int vfprintf (FILE *, const char *, void *);
>I tried changing the last formal type to (a more correct) `va_list', ...

<stdio.h> must not rely on the inclusion of <stdarg.h> nor include
<stdarg.h> itself.  The v*() declarations in <stdio.h> should have
the appropriate type directly used in the declaration (i.e. not via
a typedef), or else they should use an implementation-reserved
identifier for the typedef.  For example:
	/* <stdio.h> example implementation (partial) */
	#include <sys/cdefs>	/* defines __va_list etc. */
	/* [FILE defined here] */
	int vfprintf(FILE *, const char *, __va_list);
With this technique, the same file (<sys/cdefs>) can be used in the
implementation of both <stdio.h> and <stdarg.h>.



More information about the Comp.std.c mailing list