1 .\" $NetBSD: varargs.3,v 1.5 2003/04/16 16:11:19 wiz 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
35 .\" (#)stdarg.3 8.1 (Berkeley) 6/5/93
36 .\" NetBSD: stdarg.3,v 1.11 2002/02/04 18:27:38 kleink Exp
43 .Nd variable argument lists
47 .Fn va_start "va_list ap"
49 .Fn va_arg "va_list ap" type
51 .Fn va_end "va_list ap"
54 These historic interfaces are provided to support compilation of
55 existing programs only.
56 New code should use the
61 A function may be called with a varying number of arguments of varying
67 and defines three macros for stepping
68 through a list of arguments whose number and types are not known to
71 The called function must name an argument
73 which marks the start of the variable argument list,
74 and which is naturally the last argument named.
77 which should not be followed by a semicolon.
78 The called function also must declare an object of type
80 which is used by the macros
94 and must be called first.
98 to be the only parameter to a function, resulting in it being possible
99 for a function to have no fixed arguments preceding the variable
104 macro returns no value.
108 macro expands to an expression that has the type and value of the next
109 argument in the call.
120 so that the next call returns the next argument.
123 is a type name specified so that the type of a pointer to an
124 object that has the specified type can be obtained simply by
129 If there is no next argument, or if
131 is not compatible with the type of the actual next argument
132 (as promoted according to the default argument promotions),
133 random errors will occur.
137 macro after that of the
139 macro returns the argument after
141 Successive invocations return the values of the remaining
146 macro handles a normal return from the function whose variable argument
147 list was initialized by
152 macro returns no value.
156 takes a string of format characters and prints out the argument
157 associated with each format character based on the type.
158 .Bd -literal -offset indent
159 void foo(fmt, va_alist)
170 case 's': /* string */
171 s = va_arg(ap, char *);
172 printf("string %s\en", s);
176 printf("int %d\en", d);
179 c = va_arg(ap, char);
180 printf("char %c\en", c);
190 These historic macros were replaced in
200 compatible with the new macros they were replaced by.
201 In particular, it is not possible for a
203 function to have no fixed arguments.