macro

va_start

<cstdarg>
void va_start ( va_list ap, paramN );
Initialize a variable argument list
Initializes the object of type va_list passed as argument ap to hold the information needed to retrieve the additional arguments after parameter paramN with function va_arg.

A function that executes va_start, shall also execute va_end before it returns.

Parameters

ap
Object of type va_list that will hold the information needed to retrieve the additional arguments with va_arg.
paramN
Parameter name of the last named parameter in the function definition.

Return Value

none

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* va_start example */
#include <stdio.h>
#include <stdarg.h>

void PrintFloats ( int amount, ...)
{
  int i;
  double val;
  printf ("Floats passed: ");
  va_list vl;
  va_start(vl,amount);
  for (i=0;i<amount;i++)
  {
    val=va_arg(vl,double);
    printf ("\t%.2f",val);
  }
  va_end(vl);
  printf ("\n");
}

int main ()
{
  PrintFloats (3,3.14159,2.71828,1.41421);
  return 0;
}


The function PrintFloats takes as its first parameter, amount, the number of additional arguments, which are then read using the cstdarg macros and printed out with a specific format.

See also