HP 3000 Manuals

va_start [ HP C/iX Library Reference Manual ] MPE/iX 5.0 Documentation


HP C/iX Library Reference Manual

va_start 

Initializes a variable to the beginning of an argument list.

Syntax 

     #include <stdarg.h>
     void va_start (va_list ap, parmN);

Parameters 

ap            A pointer to a double, as defined by type va_list in
              <varargs.h>.

parmN         The identifier of the rightmost parameter in the variable
              parameter list in the function definition.  This is the
              identifier just before the horizontal ellipsis.

Return Values 

None.

Description 

The va_start macro initializes ap (of type va_list) for subsequent use by
va_arg and va_end.  It must be invoked before va_arg can be used.

The macros va_start, va_arg, and va_end determine the arguments of a
function that can be called with a variable number of arguments.  The
variable number of arguments are indicated by the ellipsis in the
function header.


NOTE The header <varargs.h> also contains this macro. However, <varargs.h> is not defined by the ANSI C standard.
Examples The following program uses <stdarg.h>: #include <stdarg.h> #include <stdio.h> enum arglisttype {NO_VAR_LIST, VAR_LIST_PRESENT}; enum argtype {END_OF_LIST, CHAR, DOUB, INT, PINT}; int func (int a1, enum arglisttype a2, ...) { va_list ap; enum argtype ptype; int i, *p; char c; double d; printf ("arg count = %d\n", a1); if (a2 == VAR_LIST_PRESENT) { /* Initialize the varargs mechanism */ va_start(ap, a2); /* pass a2 as an anchor */ /* pick up all the arguments */ do { /* get the type of the argument */ ptype = va_arg (ap, enum argtype); /* retrieve the argument based on the type */ switch (ptype) { case CHAR: c = va_arg (ap, char); printf ("char = %c\n", c); break; case DOUB: d = va_arg (ap, double); printf ("double = %f\n", d); break; case PINT: p = va_arg (ap, int *); printf ("pointer = %x\n", p); break; case INT : i = va_arg (ap, int); printf ("int = %d\n", i); break; case END_OF_LIST : break; default: printf ("bad argument type %d\n", ptype); ptype = END_OF_LIST; /* to break loop */ break; } /* switch */ } while (ptype != END_OF_LIST); /* Clean up */ va_end (ap); } /* if */ } main() { int x = 99; func (1, NO_VAR_LIST); func (2, VAR_LIST_PRESENT, DOUB, 3.0, PINT, &x, END_OF_LIST); } See Also va_arg, va_end, ANSI C 4.8.1.1


MPE/iX 5.0 Documentation