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. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)stdarg.3 8.1 (Berkeley) 6/5/93
40 .Nd variable argument lists
44 .Fn va_start "va_list ap" last
46 .Fn va_arg "va_list ap" type
48 .Fn va_copy "va_list dest" "va_list src"
50 .Fn va_end "va_list ap"
52 A function may be called with a varying number of arguments of varying
58 and defines four macros for stepping
59 through a list of arguments whose number and types are not known to
62 The called function must declare an object of type
64 which is used by the macros
80 and must be called first.
84 is the name of the last parameter before the variable argument list,
85 i.e., the last parameter of which the calling function knows the type.
87 Because the address of this parameter is used in the
89 macro, it should not be declared as a register variable, or as a
90 function or an array type.
94 macro expands to an expression that has the type and value of the next
108 so that the next call returns the next argument.
111 is a type name specified so that the type of a pointer to an
112 object that has the specified type can be obtained simply by
117 If there is no next argument, or if
119 is not compatible with the type of the actual next argument
120 (as promoted according to the default argument promotions),
121 random errors will occur.
125 macro after that of the
127 macro returns the argument after
129 Successive invocations return the values of the remaining
134 macro copies a variable argument list, previously initialized by
140 The state is preserved such that it is equivalent to calling
142 with the same second argument used with
146 the same number of times as called with
151 macro cleans up any state associated with the variable argument list
158 must be paired with a corresponding invocation of
160 in the same function.
164 macro returns the value of the next argument.
171 macros return no value.
175 takes a string of format characters and prints out the argument
176 associated with each format character based on the type.
177 .Bd -literal -offset indent
178 void foo(char *fmt, ...)
187 case 's': /* string */
188 s = va_arg(ap, char *);
189 printf("string %s\en", s);
193 printf("int %d\en", d);
196 /* Note: char is promoted to int. */
198 printf("char %c\en", c);
207 compatible with the historic macros they replace.
208 A backward compatible version can be found in the include
226 macros were introduced in
230 macro was introduced in
237 macros do not permit programmers to
238 code a function with no fixed arguments.
239 This problem generates work mainly when converting
244 but it also creates difficulties for variadic functions that
245 wish to pass all of their arguments on to a function