prototypes required ?

Stephen Clamage steve at taumet.com
Sat Oct 20 04:36:51 AEST 1990


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 that a header must declare or define all identifiers
in its associated section.  I find it hard to read the standard to say
that non-prototype declarations are OK, but that may be prejudice.  I
haven't found an explicit statement that full prototypes are required.

! ... 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!

Yes, they cheated, and this is not standard-conforming.  The prototype
must match the one in the standard.

!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)?

<stdio.h> cannot just #include <stdarg.h>, since no header may include
any of the others.  The implementor cannot require you to #include
<stdarg.h> prior to <stdio.h>.  The implementor must supply a prototype for
functions which are equivalent to using the typedefs in the non-included
header file.  The implementor supplies all the headers, so this is
possible, apart from being required.

So in <stdarg.h> we might have:
	struct _T { .... };
	typedef struct _T va_list[2];

Then in <stdio.h> we would have:
	struct _T;
	int vfprintf(FILE *, const char*, struct _T*);	

This meets all of the ANSI requirements.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.std.c mailing list