va_start -- Begin Varying-Length Argument List Processing

SYNOPSIS

 #include <stdarg.h>

 void va_start(va_list ap, arg_name);
 

DESCRIPTION

va_start initializes processing of a varying-length argument list. The first argument, ap, is a work area of type va_list, which is used by the expansions of the various <stdarg.h> macros. The second argument, arg_name, is the name of the parameter to the calling function after which the varying part of the parameter list begins.

This function is one of three macros used to advance through a list of arguments whose number and type are unknown when the function is compiled. The other two macros are

va_arg
accesses an argument from a varying-length argument list.
va_end
ends varying-length argument list processing.
These macros and the type va_list are defined in the header file <stdarg.h>.

The type va_list defines a buffer that is used as a work area during argument list processing. A routine that accepts a varying number of arguments must declare an auto variable of this type.

In general, a function that uses the <stdarg.h> facilities has this form:

 #include <stdarg.h>

    /* The arguments in the list are the ones that must */ 
    /*  always be present.                              */ 
 func( type  arg1, type  arg2)
 {
    va_list ap;      /* Declare stdarg work area.       */ 

       /* Note that first varying-length argument       */ 
       /*  follows arg2 in the list.                    */ 
    va_start(ap, arg2);

    while (more_args_expected) {

          /* Get next argument value.                   */ 
       this_arg = va_arg(ap, type);
       process(this_arg);
    }
    va_end(ap);      /* finished argument processing    */
 }
 

RETURN VALUE

va_start has no return value.

CAUTION

The results of va_start are unpredictable if the argument values are not appropriate.

EXAMPLE

See the example for va_arg.

RELATED FUNCTIONS

va_arg, va_end

SEE ALSO

Varying-Length Argument List Functions

Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.