[comp.lang.c] How do you build a varargs argument list?

sean@etnibsd.UUCP (Sean McElroy) (10/10/89)

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

gwyn@smoke.BRL.MIL (Doug Gwyn) (10/11/89)

In article <1070@etnibsd.UUCP> sean@etnibsd.UUCP (Sean McElroy) writes:
>I'd like to know if there is a standard way of building a varargs
>format argument list which is implementation independent

No, not an official varargs/stdarg argument list.
You can accomplish a similar function using ordinary C data structures.

>You want to print the data using vprintf:

But not if you insist on this.

>... there is no varargs constructor.  Any reason for this?

"Limited utility."