.TH "va_arg()" "" "" "Variable Arguments"
.PC "Return pointer to next argument in argument list
.B "#include <stdarg.h>"
\fItypename \fB*va_arg(\fIlistptr\^\fB, \fItypename\^\fB)\fR
\fBva_list \fIlistptr\^\fB, \fItypename\^\fB;\fR
.sp \n(pDu
.B "#include <varargs.h>"
\fItypename \fB*va_arg(\fIlistptr\^\fB, \fItypename\^\fB)\fR
\fBva_list \fIlistptr\^\fB, \fItypename\^\fB;\fR
.PP
.B va_arg()
returns a pointer to the next argument in an argument list.
It can be used with functions that take a variable number of arguments,
such as
.B printf()
or
.BR scanf() ,
to help write such functions portably.
It is always used with
.B va_end()
and
.B va_start()
within a function that takes a variable number of arguments.
.PP
.I listptr
is of type
.BR va_list ,
which is defined in the headers
.B <stdarg.h>
and
.BR <varargs.h> .
This object must first be initialized by the macro
.BR va_start() .
.PP
.I typename
is the name of the type for which
.B va_arg()
is to return a pointer.
For example, if you wish
.B va_arg()
to return a pointer to an integer,
.I typename
should be of type
.BR int .
.PP
.B va_arg()
can only handle \*(QLstandard\*(QR data types,
i.e., those data types that can be transformed to pointers
by appending an asterisk \*(Ql*\*(Qr.
.SH Example
For an example of this macro, see the entry for
.BR "stdarg.h" .
.SH "See Also"
.Xr "stdarg.h," stdarg.h
.Xr "varargs.h" varargs.h
.br
\*(AS, \(sc7.8.1.2
.SH Notes
There are two different versions of
.BR va_arg() :
the ANSI version, which is defined in
.BR <stdarg.h> ;
and the \*(UN version, which is defined in
.BR <varargs.h> .
For a discussion of how these implementations differ, see the entry for
.BR stdarg.h .
.PP
If there is no next argument for
.B va_arg()
to handle, or if
.I typename
is incorrect, then the behavior of
.B va_arg()
is undefined.
.PP
The ANSI Standard demands that
.B va_arg()
be implemented only as a macro.
If its macro definition is suppressed within a program,
its behavior is undefined.
