1 .\" $NetBSD: stdarg.3,v 1.17 2003/08/07 10:31:01 agc Exp $
3 .\" Copyright (c) 1990, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" This code is derived from software contributed to Berkeley by
7 .\" the American National Standards Committee X3, on Information
8 .\" Processing Systems.
10 .\" Redistribution and use in source and binary forms, with or without
11 .\" modification, are permitted provided that the following conditions
13 .\" 1. Redistributions of source code must retain the above copyright
14 .\" notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\" notice, this list of conditions and the following disclaimer in the
17 .\" documentation and/or other materials provided with the distribution.
18 .\" 3. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)stdarg.3 8.1 (Berkeley) 6/5/93
45 .Nd variable argument lists
49 .Fn va_start "va_list ap" last
51 .Fn va_arg "va_list ap" type
53 .Fn va_copy "va_list dest" "va_list src"
55 .Fn va_end "va_list ap"
57 A function may be called with a varying number of arguments of varying
63 and defines three macros for stepping
64 through a list of arguments whose number and types are not known to
67 The called function must declare an object of type
69 which is used by the macros
85 and must be called first.
89 is the name of the last parameter before the variable argument list,
90 i.e. the last parameter of which the calling function knows the type.
92 Because the address of this parameter is used in the
94 macro, it should not be declared as a register variable, or as a
95 function or an array type.
99 macro returns no value.
103 macro expands to an expression that has the type and value of the next
104 argument in the call.
115 so that the next call returns the next argument.
118 is a type name specified so that the type of a pointer to an
119 object that has the specified type can be obtained simply by
124 If there is no next argument, or if
126 is not compatible with the type of the actual next argument
127 (as promoted according to the default argument promotions),
128 random errors will occur.
130 If the type in question is one that gets promoted, the promoted type
131 should be used as the argument to
133 The following describes which types are promoted (and to what):
151 macro after that of the
153 macro returns the argument after
155 Successive invocations return the values of the remaining
166 macro had been applied to it followed by the same sequence of uses of the
168 macro as had previously been used to reach the present state of
173 macro returns no value.
177 macro handles a normal return from the function whose variable argument
178 list was initialized by
185 macro returns no value.
189 takes a string of format characters and prints out the argument
190 associated with each format character based on the type.
191 .Bd -literal -offset indent
203 case 's': /* string */
204 s = va_arg(ap, char *);
205 printf("string %s\en", s);
209 printf("int %d\en", d);
212 c = va_arg(ap, int); /* promoted */
213 printf("char %c\en", c);
215 case 'f': /* float */
216 f = va_arg(ap, double); /* promoted */
217 printf("float %f\en", f);
237 macros were introduced in
241 macro was introduced in
246 compatible with the historic macros they replace.
247 A backward compatible version can be found in the include
255 macros do not permit programmers to
256 code a function with no fixed arguments.
257 This problem generates work mainly when converting
262 but it also creates difficulties for variadic functions that
263 wish to pass all of their arguments on to a function