<varargs.h> for Turbo C ?

Doug Gwyn gwyn at smoke.BRL.MIL
Mon Oct 16 13:46:18 AEST 1989


In article <5940012 at hpcupt1.HP.COM> swh at hpcupt1.HP.COM (Steve Harrold) writes:
>Even though the <stdarg.h> file has definitions for "va_start", "va_arg",
>and so on, these definitions are not the same as found in the <varargs.h>
>file.

That's right.  <stdarg.h> facilities were based on traditional <varargs.h>,
with some adjustments deemed to be necessary in some potential implementation
environments:

	variadic functions require special ,... declaration syntax
	so the compiler can give them special linkage if necessary

	va_alist and va_dcl are replaced by the ,... style function
	header

	va_start() is given a fixed argument as a "handle" to allow
	the implementation to know where the variadic arguments are

	va_list may be, but is not required to be, an array type

>Even though the files are short, the #defines are rather convoluted, 
>rather reminiscent of APL style coding.  

That's okay, you shouldn't be looking at them.

>Rather than spend the time to study how stacks are created and manipulated 
>by the Turbo C compiler and then to produce a reliable "port" of Turbo C's
><stdarg.h> file to <varargs.h> (including the labor of creating test
>cases), I've always resorted to dropping Turbo C for Microsoft C whenever
>I handle source code that uses <varargs.h>.
>I'm still hopeful that some kind soul will step forward with a solution.

I already suggested a solution, namely, convert the code to use the
equivalent <stdarg.h> facilities.  Here is a typical example of code
that works with either implementation:

	/* typical declaration, e.g. in a package interface header: */

	#ifdef __STDC__
	extern void	ErPrintf( const char *, ... );
	#else
	extern void	ErPrintf();
	#endif


	/* typical definition: */

	#ifdef __STDC__
	#include	<stdarg.h>
	#else
	#include	<varargs.h>
	#endif

	#ifdef __STDC__
	void
	ErPrintf( const char *format, ... )
	#else
	/*VARARGS*/
	void
	ErPrintf( va_alist )
		va_dcl
	#endif
		{
	#ifndef __STDC__
		register const char	*format;
	#endif
		va_list			ap;

	#ifdef __STDC__
		va_start( ap, format );
	#else
		va_start( ap );
		format = va_arg( ap, const char * );
	#endif
		(void)vfprintf( stderr, format, ap );
		(void)fflush( stderr );
		va_end( ap );
		}



More information about the Comp.lang.c mailing list