🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1868

Re: prototypes required ?

#1868
From: Stephen Clamage
Date: Fri, 19 Oct 1990 18:36
49 lines
2620 bytes
rfg@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@taumet.com
Technical Details
Message-ID: <483@taumet.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!rutgers!psuvax1!wuarchive!uunet!taumet!steve
References: <4026@otis.oakhill.UUCP> <14164@smoke.BRL.MIL> <2150@lupine.NCD.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!rutgers!psuvax1!wuarchive!uunet!taumet!steve
From: steve@taumet.com (Stephen Clamage)
Newsgroups: comp.std.c
Subject: Re: prototypes required ?
Keywords: printf stdargs prototypes
Message-ID: <483@taumet.com>
Date: 19 Oct 90 18:36:51 GMT
References: <4026@otis.oakhill.UUCP> <14164@smoke.BRL.MIL> <2150@lupine.NCD.COM>
Organization: Taumetric Corporation, San Diego
Lines: 49