HP C/iX Library Reference Manual (30026-90004)
384 Chapter5
HP C/iX Library Function Descriptions
va_start
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);
}