va_list used in <stdio.h>

Doug Gwyn gwyn at smoke.BRL.MIL
Fri Aug 18 01:42:21 AEST 1989


In article <13572 at bloom-beacon.MIT.EDU> scs at adam.pika.mit.edu (Steve Summit) writes:
>...which is difficult if the implementor of <stdio.h> is not also
>the implementor of <stdarg.h>.

It is, reasonably I think, assumed that the Standard C implementation
on a system is provided as a single integrated whole, rather than
assembled piecemeal from several uncooperative sources.

>deep breath, and add something like va_list.h:
>	#ifndef _VA_LIST
>	#define _VA_LIST
>	typedef int *__va_list;
>	#endif
><stdarg.h> would then contain
>	#include <va_list.h>
>	typedef __va_list va_list;
>and <stdio.h> would contain
>	#include <va_list.h>
>	extern int vfprintf(FILE *, char *, __va_list);

That's one way to correctly implement these headers (except that
the "char*" parameter should be "const char*").

>(I'd probably have to do the same thing for off_t, because
>if fseek() doesn't take one, it should.  Schade, off_t is in
>1003.1's baliwick, not X3J11's.)

Also note that size_t and NULL are defined in more than one standard
header; NULL is not much of a problem because of benign redefinition,
but since size_t is a typedef it must be protected by some sort of
one-time interlock.

>It is apparently impossible to write a correct, standalone <stdio.h>,
>which is what Dale Schumacher is trying to do.

Sure it is, along the lines I suggested.  It just won't be fully
portable, that's all.  But nobody claimed that a fully portable
implementation of the standard C library was possible in the
first place.

Actually I don't think you are absolutely required to use prototypes
in the standard header function declarations, except for the ,...
functions (which vfprintf() is not).

>Also in article <10720 at smoke.BRL.MIL>, Doug writes:
>>Warning!  Use __iob or _Iob, not _iob, in your <stdio.h>.
>I'm not sure what is implied here.

You should read Sue Meloy's article in the Journal of C Language
Translation.  Consider:

	#include <stdio.h>
	func() {
		int _iob;
		_iob = getchar();
	}



More information about the Comp.lang.c mailing list