[comp.std.c] vprintf

chin@ankh.ankh.ftl.fl.us (Albert Chin) (07/28/90)

Is vprintf() mandated to be in <stdio.h> by ANSI C. My "ANSI" compiler doesn't
have it and I have not been able to find sources of it anywhere.

albert chin ... mthvax!mamia!albert

colin@array.UUCP (Colin Plumb) (07/29/90)

In article <CHIN.90Jul28003642@ankh.ankh.ftl.fl.us> chin@ankh.ankh.ftl.fl.us (Albert Chin) writes:
> Is vprintf() mandated to be in <stdio.h> by ANSI C. My "ANSI" compiler doesn't
> have it and I have not been able to find sources of it anywhere.

Section 4. (Library)
	9. (Input/Output <stdio.h>)
	6. (Formatted input/output functions)
	8. (The vprintf function)

You must #include <stdarg.h> and <stdio.h>
-- 
	-Colin

henry@zoo.toronto.edu (Henry Spencer) (07/29/90)

In article <CHIN.90Jul28003642@ankh.ankh.ftl.fl.us> chin@ankh.ankh.ftl.fl.us (Albert Chin) writes:
>Is vprintf() mandated to be in <stdio.h> by ANSI C...

Yes.  (Although you have to include <stdarg.h> as well.)
-- 
The 486 is to a modern CPU as a Jules  | Henry Spencer at U of Toronto Zoology
Verne reprint is to a modern SF novel. |  henry@zoo.toronto.edu   utzoo!henry

steve@taumet.com (Stephen Clamage) (07/29/90)

chin@ankh.ankh.ftl.fl.us (Albert Chin) writes:

>Is vprintf() mandated to be in <stdio.h> by ANSI C.

Yes, in a "hosted" implementation.  Section 4.9.6.8 of the standard.

> My "ANSI" compiler doesn't have it ...

Complain to the vendor.  It is not an ANSI-conforming compiler (in a
"hosted" implementation) if vprintf() is missing.  To implement vprintf(),
you usually need to know the underlying implementation of printf().
The various members of the printf() family generally set up a call to
a special function (often called something like _doprint).  You need to
know what this is and how to call it in order to implement vprintf().
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com

gwyn@smoke.BRL.MIL (Doug Gwyn) (07/29/90)

In article <CHIN.90Jul28003642@ankh.ankh.ftl.fl.us> chin@ankh.ankh.ftl.fl.us (Albert Chin) writes:
>Is vprintf() mandated to be in <stdio.h> by ANSI C. My "ANSI" compiler doesn't
>have it and I have not been able to find sources of it anywhere.

Your terminology is a bit loose, but yes, the C standard requires that
inclusion of <stdio.h> result in (among other things) a declaration for
the vprintf() library function, which the standard library is required
to provide.

In general, vprintf() cannot be readily implemented in terms of other
standard library functions, which is why the implementation is supposed
to provide it for you.

gwyn@smoke.BRL.MIL (Doug Gwyn) (07/30/90)

In article <1990Jul28.211947.3795@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes:
>In article <CHIN.90Jul28003642@ankh.ankh.ftl.fl.us> chin@ankh.ankh.ftl.fl.us (Albert Chin) writes:
>>Is vprintf() mandated to be in <stdio.h> by ANSI C...
>Yes.  (Although you have to include <stdarg.h> as well.)

You don't have to include <stdarg.h> to get vprintf() properly defined,
just <stdio.h>.  However, you need <stdarg.h> for the application to
make much use of vprintf().

henry@zoo.toronto.edu (Henry Spencer) (07/31/90)

In article <13450@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
>>>Is vprintf() mandated to be in <stdio.h> by ANSI C...
>>Yes.  (Although you have to include <stdarg.h> as well.)
>
>You don't have to include <stdarg.h> to get vprintf() properly defined,
>just <stdio.h>...

Can you prove this?  Unless this got changed since the late draft that
is all I've got (must get a copy of the final standard, sigh...), the
specs for the v* functions all call for <stdarg.h> before <stdio.h>.
On a quick search, I find no explicit statement to the effect that
either (a) <stdio.h> suffices, or (b) <stdarg.h> is required.
-- 
The 486 is to a modern CPU as a Jules  | Henry Spencer at U of Toronto Zoology
Verne reprint is to a modern SF novel. |  henry@zoo.toronto.edu   utzoo!henry

gwyn@smoke.BRL.MIL (Doug Gwyn) (07/31/90)

In article <1990Jul30.182656.19169@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes:
>In article <13450@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
>>>>Is vprintf() mandated to be in <stdio.h> by ANSI C...
>>>Yes.  (Although you have to include <stdarg.h> as well.)
>>You don't have to include <stdarg.h> to get vprintf() properly defined,
>>just <stdio.h>...
>Can you prove this?  Unless this got changed since the late draft that
>is all I've got (must get a copy of the final standard, sigh...), the
>specs for the v* functions all call for <stdarg.h> before <stdio.h>.
>On a quick search, I find no explicit statement to the effect that
>either (a) <stdio.h> suffices, or (b) <stdarg.h> is required.

4.1.2.1 states that the header for the section (4.9, i.e. <stdio.h>)
declares or defines all identifiers listed for its section; it doesn't
say or imply that it may need any help in doing so.  The "Synopsis"
subsections are just a funny sort of pseudo-source method of showing
what the function interfaces are like; in fact, as 4.1.6 points out,
in most cases the functions can be declared without use of any
standard header.  The reason for <stdarg.h> in the v*printf() Synopses
is that the interface is shown in terms of the va_list type, and
inclusion of <stdarg.h> is the only method by which a strictly
conforming application could get that type defined.  Note, however,
that a conforming implementation must NOT naively invoke <stdarg.h>
to obtain a definition for va_list for use in the v*printf()
declarations within <stdio.h>.  This was explained in the response to
a letter in the third round of public review of the draft proposed
standard:

	Response to Letter 185 (X3J11/88-145) issue summarized as
	"va_list must also be defined in stdio.h>":

	va_list need not, indeed must not, be defined in <stdio.h>.

	typedefs do not create new types, merely synonyms for other
	types.  In <stdio.h> function prototypes an implementation
	has to use the type that it would define for va_list in
	<stdarg.h>.  For example, if a void * is chosen for va_list,
	the prototype for vprintf, vfprintf, and vsprintf would just
	use void *.

This question has come up several times, and that has always been the
response.

bengsig@oracle.nl (Bjorn Engsig) (07/31/90)

In articles <1990Jul30.182656.19169@zoo.toronto.edu> and <13450@smoke.BRL.MIL> 
henry@zoo.toronto.edu (Henry Spencer) and gwyn@smoke.BRL.MIL (Doug Gwyn) have
a discussion:

Doug:
|You don't have to include <stdarg.h> to get vprintf() properly defined,
|just <stdio.h>...
Henry:
|Can you prove this?

Isn't it wonderful for the rest of us that the guru's also disagree sometimes?
What about Karl or Chris, don't you have a comment to this interesting discus-
sion.  I would very much like to know if I need to include <stdarg.h> in all
those sources where I only need to define vprintf() but don't call it :-)
-- 
Bjorn Engsig,	Domain:		bengsig@oracle.nl, bengsig@oracle.com
		Path:		uunet!mcsun!orcenl!bengsig

libes@cme.nist.gov (Don Libes) (08/06/90)

In article <924@nlsun1.oracle.nl> bengsig@oracle.nl (Bjorn Engsig) writes:
>Doug:  You don't have to include <stdarg.h> to get vprintf() properly defined,
>       just <stdio.h>...
>Henry: Can you prove this?

>Isn't it wonderful for the rest of us that the guru's also disagree sometimes?
>What about Karl or Chris, don't you have a comment to this interesting discus-
>sion.  I would very much like to know if I need to include <stdarg.h> in all
>those sources where I only need to define vprintf() but don't call it :-)

This month's C Users Journal has an article by Plauger (X3J11 secretary)
which discusses this very point at length.  In brief, he agrees with
Doug, however the article goes into some detail about why this is an
important issue and some suggested implementation notes.

Since the standard was passed, Plauger has been writing interpretation
articles in CUJ that I've found fascinating and very well written.  For
instance, they include a lot of historical background, misperceptions,
caveats, implementation suggestions and examples.

Don Libes          libes@cme.nist.gov      ...!uunet!cme-durer!libes