1 .\" $NetBSD: stdarg.3,v 1.3 1994/11/30 15:24:37 jtc 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. All advertising materials mentioning features or use of this software
19 .\" must display the following acknowledgement:
20 .\" This product includes software developed by the University of
21 .\" California, Berkeley and its contributors.
22 .\" 4. Neither the name of the University nor the names of its contributors
23 .\" may be used to endorse or promote products derived from this software
24 .\" without specific prior written permission.
26 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 .\" @(#)stdarg.3 8.1 (Berkeley) 6/5/93
45 .Nd variable argument lists
47 .Fd #include <stdarg.h>
49 .Fn va_start "va_list ap" last
51 .Fn va_arg "va_list ap" type
53 .Fn va_end "va_list ap"
55 A function may be called with a varying number of arguments of varying
61 and defines three macros for stepping
62 through a list of arguments whose number and types are not known to
65 The called function must declare an object of type
67 which is used by the macros
81 and must be called first.
85 is the name of the last parameter before the variable argument list,
86 i.e. the last parameter of which the calling function knows the type.
88 Because the address of this parameter is used in the
90 macro, it should not be declared as a register variable, or as a
91 function or an array type.
95 macro returns no value.
99 macro expands to an expression that has the type and value of the next
100 argument in the call.
111 so that the next call returns the next argument.
114 is a type name specified so that the type of a pointer to an
115 object that has the specified type can be obtained simply by
120 If there is no next argument, or if
122 is not compatible with the type of the actual next argument
123 (as promoted according to the default argument promotions),
124 random errors will occur.
128 macro after that of the
130 macro returns the argument after
132 Successive invocations return the values of the remaining
137 macro handles a normal return from the function whose variable argument
138 list was initialized by
143 macro returns no value.
147 takes a string of format characters and prints out the argument
148 associated with each format character based on the type.
149 .Bd -literal -offset indent
150 void foo(char *fmt, ...)
159 case 's': /* string */
160 s = va_arg(ap, char *);
161 printf("string %s\en", s);
165 printf("int %d\en", d);
168 c = va_arg(ap, char);
169 printf("char %c\en", c);
186 compatible with the historic macros they replace.
187 A backward compatible version can be found in the include
195 macros do not permit programmers to
196 code a function with no fixed arguments.
197 This problem generates work mainly when converting
202 but it also creates difficulties for variadic functions that
203 wish to pass all of their arguments on to a function