1 .\" Copyright (c) 1990, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the American National Standards Committee X3, on Information
6 .\" Processing Systems.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. All advertising materials mentioning features or use of this software
17 .\" must display the following acknowledgement:
18 .\" This product includes software developed by the University of
19 .\" California, Berkeley and its contributors.
20 .\" 4. Neither the name of the University nor the names of its contributors
21 .\" may be used to endorse or promote products derived from this software
22 .\" without specific prior written permission.
24 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 .\" @(#)stdarg.3 8.1 (Berkeley) 6/5/93
37 .\" $FreeBSD: src/share/man/man3/stdarg.3,v 1.15 2005/01/21 08:36:36 ru Exp $
44 .Nd variable argument lists
48 .Fn va_start "va_list ap" last
50 .Fn va_arg "va_list ap" type
52 .Fn va_copy "va_list dest" "va_list src"
54 .Fn va_end "va_list ap"
56 A function may be called with a varying number of arguments of varying
62 and defines three macros for stepping
63 through a list of arguments whose number and types are not known to
66 The called function must declare an object of type
68 which is used by the macros
77 macro must be called first, and it initializes
79 which can be passed to
81 for each argument to be processed.
84 signals that there are no further arguments, and causes
87 Note that each call to
89 must be matched by a call to
91 from within the same function.
95 is the name of the last parameter before the variable argument list,
96 i.e., the last parameter of which the calling function knows the type.
98 Because the address of this parameter is used in the
100 macro, it should not be declared as a register variable, or as a
101 function or an array type.
105 macro expands to an expression that has the type and value of the next
106 argument in the call.
117 so that the next call returns the next argument.
120 is a type name specified so that the type of a pointer to an
121 object that has the specified type can be obtained simply by
126 If there is no next argument, or if
128 is not compatible with the type of the actual next argument
129 (as promoted according to the default argument promotions),
130 random errors will occur.
134 macro after that of the
136 macro returns the argument after
138 Successive invocations return the values of the remaining
143 macro copies the state of the variable argument list,
145 previously initialized by
147 to the variable argument list,
149 which must not have been previously initialized by
151 without an intervening call to
153 The state preserved in
155 is equivalent to calling
161 in the same way as was used on
163 The copied variable argument list can subsequently be passed to
165 and must finally be passed to
167 when through with it.
169 After a variable argument list is invalidated by
171 it can be reinitialized with
173 or made a copy of another variable argument list with
178 takes a string of format characters and prints out the argument
179 associated with each format character based on the type.
180 .Bd -literal -offset indent
181 void foo(char *fmt, ...)
191 case 's': /* string */
192 s = va_arg(ap, char *);
193 printf("string %s\en", s);
197 printf("int %d\en", d);
200 /* Note: char is promoted to int. */
202 printf("char %c\en", c);
207 /* use ap2 to iterate over the arguments again */
215 compatible with the historic macros they replace.
216 A backward compatible version can be found in the include
233 macros do not permit programmers to
234 code a function with no fixed arguments.
235 This problem generates work mainly when converting
240 but it also creates difficulties for variadic functions that
241 wish to pass all of their arguments on to a function