How do you build a varargs argument list?

Sean McElroy sean at etnibsd.UUCP
Tue Oct 10 04:17:31 AEST 1989


I'd like to know if there is a standard way of building a varargs
format argument list which is implementation independent (i.e.
doesn't count on the existence of a (single) call frame pointer).

Your program reads a socket which contains some arbitrary encoding
of data items to be composed into a list, terminated somehow, and to
be printed.

You want to print the data using vprintf:

#include <stdarg.h>
#include <stdio.h>
int vprintf(format, ap)
char *format;
va_list ap;

This is from the man pages for vprintf(3S).  "format" is a print
specification string.  "ap" is the list of arguments used to satisfy
the format specifications contained in "format".  Assume that
we already have a way of constructing the "format" string so that
it completely represents the translation of each of the arguments in
"ap" (for example, it may be part of an initialized array of format 
strings).  How do you construct "ap"?  Note you cannot assume that "ap" has
a straight-forward implementation (such as a pointer to an "argument
list" or a "stack".)  This is especially true of RISC architectures 
where the components of a call frame may be spread out among a 
series of registers.

You can use va_start, va_arg and va_end to access members of a
varargs construct but there is no varargs constructor.  Any reason
for this?
-- 
  ____,.,_..,__.,_.,__     Sean Philip McElroy
   __'..__._,_.__.__.__    Eaton Corp., SED
   _,___`_.'__.__.__.__    108 Cherry Hill Dr., Beverly, MA 01922
  ___`..'_,___.__.__,_     uunet!etnibsd!sean



More information about the Comp.lang.c mailing list