OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man3 / stdarg.3
1 .\" Copyright (c) 1990, 1991 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the American National Standards Committee X3, on Information
6 .\" Processing Systems.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
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.
23 .\"
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
34 .\" SUCH DAMAGE.
35 .\"
36 .\"     @(#)stdarg.3    6.8 (Berkeley) 6/29/91
37 .\"
38 .\" Converted for Linux, Mon Nov 29 15:11:11 1993, faith@cs.unc.edu
39 .\" Additions, 2001-10-14, aeb
40 .\"
41 .\" Japanese Version Copyright (c) 1998 NAKANO Takeo all rights reserved.
42 .\" Translated Fri Mar 22 1998 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
43 .\" Updated Tue Oct 16 2001 by Kentaro Shirakata <argrath@ub32.org>
44 .\"
45 .TH STDARG 3  2001-10-14 "" "Linux Programmer's Manual"
46 .SH Ì¾Á°
47 stdarg, va_start, va_arg, va_end, va_copy \- ¸Ä¿ô¡¦·¿¤¬²ÄÊѤʰú¿ô¥ê¥¹¥È
48 .SH ½ñ¼°
49 .B #include <stdarg.h>
50 .sp
51 .BI "void va_start(va_list " ap ", " last );
52 .br
53 .IB type " va_arg(va_list " ap ", " type );
54 .br
55 .BI "void va_end(va_list " ap );
56 .br
57 .BI "void va_copy(va_list " dest ", va_list " src );
58 .\"O .SH DESCRIPTION
59 .SH ÀâÌÀ
60 .\"O A function may be called with a varying number of arguments of varying
61 .\"O types.
62 .\"O The include file
63 .\"O .I <stdarg.h>
64 .\"O declares a type
65 .\"O .I va_list
66 .\"O and defines three macros for stepping through a list of arguments whose
67 .\"O number and types are not known to the called function.
68 ´Ø¿ô¤Ï¸Æ¤Ó½Ð¤·¤ËºÝ¤·¤Æ¡¢¸Ä¿ô¤ä·¿¤¬²ÄÊѤʰú¿ô¤ò¤È¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
69 ¥¤¥ó¥¯¥ë¡¼¥É¥Õ¥¡¥¤¥ë
70 .I <stdarg.h>
71 ¤Ç¤Ï
72 .I va_list
73 ·¿¤¬Àë¸À¤µ¤ì¤Æ¤ª¤ê¡¢3 ¤Ä¤Î¥Þ¥¯¥í¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£¤³¤ì¤é¤òÍѤ¤¤ë¤È¡¢
74 ¸Æ¤Ó½Ð¤µ¤ì¤¿´Ø¿ô¦¤Ç¤Ï¸Ä¿ô¤ä·¿¤òÃΤé¤Ê¤¤°ú¤­¿ô¤Î¥ê¥¹¥È¤ò¡¢½ç¤Ë°ì
75 ¤Ä¤Å¤ÄÆɤ߹þ¤à¤³¤È¤¬¤Ç¤­¤ë¡£
76 .PP
77 .\"O The called function must declare an object of type
78 .\"O .I va_list
79 .\"O which is used by the macros
80 .\"O .BR va_start (),
81 .\"O .BR va_arg (),
82 .\"O and
83 .\"O .BR va_end ().
84 ¸Æ¤Ó½Ð¤µ¤ì¤ë´Ø¿ô¤Ç¤Ï¡¢
85 .I va_list
86 ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤¬Àë¸À¤µ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£¤³¤Î¥ª¥Ö¥¸¥§¥¯¥È¤¬
87 .BR va_start (),
88 .BR va_arg (),
89 .BR va_end ()
90 ¤Î³Æ¥Þ¥¯¥í¤Ë¤è¤Ã¤Æ°·¤ï¤ì¤ë¡£
91 .SS va_start()
92 .\"O The
93 .\"O .BR va_start ()
94 .\"O macro initializes
95 .\"O .I ap
96 .\"O for subsequent use by
97 .\"O .BR va_arg ()
98 .\"O and
99 .\"O .BR va_end (),
100 .\"O and must be called first.
101 .BR va_start ()
102 ¥Þ¥¯¥í¤ÏºÇ½é¤Ë¸Æ¤Ó½Ð¤µ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£¤³¤ì¤Ï
103 .I ap
104 ¤ò½é´ü²½¤·¡¢
105 .BR va_arg ()
106 ¤È
107 .BR va_end ()
108 ¤ÇÍѤ¤¤ë¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¤Ë¤¹¤ë¡£
109 .PP
110 .\"O The argument
111 .\"O .I last
112 .\"O is the name of the last argument before the variable argument list, that is,
113 .\"O the last argument of which the calling function knows the type.
114 °ú¤­¿ô
115 .I last
116 ¤Ï°ú¤­¿ô¥ê¥¹¥È¤Î¤¦¤Á¡¢²ÄÊѤÊÉôʬ¤ÎľÁ°¤ËÃÖ¤«¤ì¤ë°ú¤­¿ô¤Î̾Á°¤Ç¤¢
117 ¤ë¡£¤Ä¤Þ¤ê¸Æ¤Ó½Ð¤µ¤ì¤¿´Ø¿ô¤¬·¿¤òÃΤäƤ¤¤ëºÇ¸å¤Î°ú¤­¿ô¤Ç¤¢¤ë¡£
118 .PP
119 .\"O Because the address of this argument may be used in the
120 .\"O .BR va_start ()
121 .\"O macro, it should not be declared as a register variable,
122 .\"O or as a function or an array type.
123 ¤³¤Î°ú¤­¿ô¤Ï¥ì¥¸¥¹¥¿ÊÑ¿ô¤ä´Ø¿ô¡¢ÇÛÎó¤È¤·¤Æ
124 Àë¸À¤·¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤³¤Î°ú¤­¿ô¤Î¥¢¥É¥ì¥¹¤¬
125 .BR va_start ()
126 ¥Þ¥¯¥í¤ÇÍѤ¤¤é¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¤«¤é¤Ç¤¢¤ë¡£
127 .SS va_arg()
128 .\"O The
129 .\"O .BR va_arg ()
130 .\"O macro expands to an expression that has the type and value of the next
131 .\"O argument in the call.
132 .\"O The argument
133 .\"O .I ap
134 .\"O is the
135 .\"O .I va_list
136 .\"O .I ap
137 .\"O initialized by
138 .\"O .BR va_start ().
139 .BR va_arg ()
140 ¥Þ¥¯¥í¤Ï¡¢¸Æ¤Ó½Ð¤·»þ¤Ë»ØÄꤵ¤ì¤¿°ú¤­¿ô¤Î¤¦¤Á¡¢
141 ¼¡¤Î°ÌÃ֤ˤ¢¤ë¤â¤Î¤ò»ØÄꤷ¤¿·¿
142 .I type
143 ¤ÎÃͤȤ·¤Æ¼èÆÀ¤¹¤ë¡£
144 °ú¤­¿ô
145 .I ap
146 ¤Ï
147 .I va_list
148 .I ap
149 ¤Ç¡¢
150 .BR va_start ()
151 ¤Ë¤è¤Ã¤Æ½é´ü²½¤µ¤ì¤Æ¤¤¤ëɬÍפ¬¤¢¤ë¡£
152 .\"O Each call to
153 .\"O .BR va_arg ()
154 .\"O modifies
155 .\"O .I ap
156 .\"O so that the next call returns the next argument.
157 .\"O The argument
158 .\"O .I type
159 .\"O is a type name specified so that the type of a pointer to an object that
160 .\"O has the specified type can be obtained simply by adding a * to
161 .\"O .IR type .
162 .BR va_arg ()
163 ¤ò¸Æ¤Ó½Ð¤¹¤´¤È¤Ë
164 .I ap
165 ¤ÏÊѹ¹¤µ¤ì¡¢¼¡²ó¤Î¸Æ¤Ó½Ð¤·¤ÎºÝ¤Ë¡¢¤µ¤é¤Ë¼¡¤Î°ú¤­¿ô¤òÊÖ¤¹¤è¤¦¤Ë¤Ê¤ë¡£
166 °ú¤­¿ô
167 .I type
168 ¤Ï·¿¤Î̾Á°¤Ç¤¢¤ë¡£
169 .I type
170 ¤ÎÁ°¤Ë * ¤òÉÕ¤±¤ì¤Ð¡¢¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î·¿ÉÕ¤­¥Ý¥¤¥ó¥¿¤¬ÆÀ¤é¤ì¤ë¡£
171 .PP
172 .\"O The first use of the
173 .\"O .BR va_arg ()
174 .\"O macro after that of the
175 .\"O .BR va_start ()
176 .\"O macro returns the argument after
177 .\"O .IR last .
178 .\"O Successive invocations return the values of the remaining arguments.
179 .BR va_start ()
180 ¥Þ¥¯¥í¤Îľ¸å¤Ë
181 .BR va_arg ()
182 ¤òºÇ½é¤Ë¼Â¹Ô¤¹¤ë¤È¡¢
183 .I last
184 ¤Î¼¡¤Î°ú¤­¿ô¤¬Ê֤롣³¤±¤Æ¼Â¹Ô¤¹¤ë¤È¡¢»Ä¤ê¤Î°ú¤­¿ô¤¬¤½¤ì¤¾¤ìÊ֤롣
185 .PP
186 .\"O If there is no next argument, or if
187 .\"O .I type
188 .\"O is not compatible with the type of the actual next argument (as promoted
189 .\"O according to the default argument promotions), random errors will occur.
190 ¼¡¤Î°ú¤­¿ô¤¬¤Ê¤«¤Ã¤¿¤ê¡¢
191 .I type
192 ¤¬¼¡¤Î°ú¤­¿ô¤Î¼ÂºÝ¤Î·¿¤È¸ß´¹¤Ç¤Ê¤¤¾ì¹ç (¥Ç¥Õ¥©¥ë¥È¤Î°ú¤­¿ôÊÑ´¹¤Ç°·
193 ¤¨¤Ê¤«¤Ã¤¿¾ì¹ç) ¤Ë¤Ï¡¢Í½Â¬¤Ç¤­¤Ê¤¤¥¨¥é¡¼¤¬µ¯¤³¤ë¡£
194 .PP
195 .\"O If
196 .\"O .I ap
197 .\"O is passed to a function that uses
198 .\"O .BI va_arg( ap , type )
199 .\"O then the value of
200 .\"O .I ap
201 .\"O is undefined after the return of that function.
202 .I ap
203 ¤¬
204 .BI va_arg( ap , type )
205 ¤Î·Á¤Ç´Ø¿ô¤ËÅϤµ¤ì¤ë¤È¡¢
206 .I ap
207 ¤ÎÃͤϴؿô¤«¤éÊ֤äÆÍ褿¸å¤ÏÉÔÄê¤È¤Ê¤ë¡£
208 .SS va_end()
209 .\"O Each invocation of
210 .\"O .BR va_start ()
211 .\"O must be matched by a corresponding invocation of
212 .\"O .BR va_end ()
213 .\"O in the same function.
214 .\"O After the call
215 .\"O .BI va_end( ap )
216 .\"O the variable
217 .\"O .I ap
218 .\"O is undefined.
219 .\"O Multiple traversals of the list, each
220 .\"O bracketed by
221 .\"O .BR va_start ()
222 .\"O and
223 .\"O .BR va_end ()
224 .\"O are possible.
225 .BR va_start ()
226 ¤¬¼Â¹Ô¤µ¤ì¤ëËè¤Ë¡¢Æ±¤¸´Ø¿ôÆâ¤ÇÂбþ¤¹¤ë
227 .BR va_end ()
228 ¤¬¼Â¹Ô¤µ¤ì¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
229 .BI va_end( ap )
230 ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿¸å¡¢ÊÑ¿ô
231 .I ap
232 ¤ÎÃͤÏÉÔÄê¤È¤Ê¤ë¡£
233 .BR va_start ()
234 ¤È
235 .BR va_end ()
236 ¤ÎÁȤò²¿²ó¤âʤ٤ƻȤ¦¤³¤È¤â²Äǽ¤Ç¤¢¤ë¡£
237 .\"O .BR va_end ()
238 .\"O may be a macro or a function.
239 .BR va_end ()
240 ¤Ï¥Þ¥¯¥í¤«¤â¤·¤ì¤Ê¤¤¤·´Ø¿ô¤«¤â¤·¤ì¤Ê¤¤¡£
241 .SS va_copy()
242 .\"O .\" Proposal from clive@demon.net, 1997-02-28
243 .\"O An obvious implementation would have a
244 .\"O .I va_list
245 .\"O be a pointer to the stack frame of the variadic function.
246 ¤¹¤°Ê¬¤«¤ë
247 .I va_list
248 ¤Î¼ÂÁõ¤Ï¡¢variadic ¤Ê´Ø¿ô¤Î¥¹¥¿¥Ã¥¯¥Õ¥ì¡¼¥à¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
249 .\"argrath: variadic?
250 .\"O In such a setup (by far the most common) there seems
251 .\"O nothing against an assignment
252 ¤³¤Î¤è¤¦¤Ê¾ì¹ç(¤Û¤È¤ó¤É¤Ï¤½¤¦¤Ç¤¢¤ë)¡¢
253 ñ¤Ë°Ê²¼¤Î¤è¤¦¤Ë¤¹¤ì¤Ð¤¤¤¤¤è¤¦¤Ë»×¤¨¤ë¡£
254 .in +4n
255 .nf
256
257 va_list aq = ap;
258
259 .fi
260 .in
261 .\"O Unfortunately, there are also systems that make it an
262 .\"O array of pointers (of length 1), and there one needs
263 »ÄÇ°¤Ê¤¬¤é¡¢(Ťµ 1¤Î)¥Ý¥¤¥ó¥¿¤ÎÇÛÎó¤È¤·¤Æ°·¤¦¥·¥¹¥Æ¥à¤â¤¢¤ë¡£
264 ¤½¤Î¤è¤¦¤Ê¾ì¹ç¡¢°Ê²¼¤Î¤è¤¦¤Ë¤¹¤ëɬÍפ¬¤¢¤ë¡£
265 .in +4n
266 .nf
267
268 va_list aq;
269 *aq = *ap;
270
271 .fi
272 .in
273 .\"O Finally, on systems where arguments are passed in registers,
274 .\"O it may be necessary for
275 .\"O .BR va_start ()
276 .\"O to allocate memory, store the arguments there, and also
277 .\"O an indication of which argument is next, so that
278 .\"O .BR va_arg ()
279 .\"O can step through the list.
280 .\"O Now
281 .\"O .BR va_end ()
282 .\"O can free the allocated memory again.
283 ºÇ¸å¤Ë¡¢°ú¤­¿ô¤ò¥ì¥¸¥¹¥¿¤ÇÅϤ¹¥·¥¹¥Æ¥à¤Î¾ì¹ç¡¢
284 .BR va_start ()
285 ¤Ç¥á¥â¥ê¤ò³ä¤êÅö¤Æ¡¢°ú¤­¿ô¤ò³ÊǼ¤·¡¢
286 ¼¡¤Î°ú¤­¿ô¤¬¤É¤ì¤«¤ò»Ø¤·¼¨¤¹¤è¤¦¤Ë¤¹¤ëɬÍפ¬¤¢¤ë¡£
287 ¤½¤·¤Æ
288 .BR va_arg ()
289 ¤Ç¥ê¥¹¥È¤ò½çÈ֤ˤ¿¤É¤ê¡¢
290 .BR va_end ()
291 ¤Ç³ä¤êÅö¤Æ¤¿¥á¥â¥ê¤ò³«Êü¤¹¤ë¡£
292 .\"O To accommodate this situation, C99 adds a macro
293 .\"O .BR va_copy (),
294 .\"O so that the above assignment can be replaced by
295 ¤³¤Î¤è¤¦¤Ê¾õ¶·¤ËÂбþ¤¹¤ë¤¿¤á¡¢C99 ¤Ç¤Ï
296 .BR va_copy ()
297 ¥Þ¥¯¥í¤òÄɲä·¡¢
298 Á°½Ò¤Î¤è¤¦¤Ê³ä¤êÅö¤Æ¤Ï°Ê²¼¤Î¤è¤¦¤ËÃÖ¤­´¹¤¨¤é¤ì¤ë¤è¤¦¤Ë¤·¤¿¡£
299 .in +4n
300 .nf
301
302 va_list aq;
303 va_copy(aq, ap);
304 \&...
305 va_end(aq);
306
307 .fi
308 .in
309 .RE
310 .\"O Each invocation of
311 .\"O .BR va_copy ()
312 .\"O must be matched by a corresponding invocation of
313 .\"O .BR va_end ()
314 .\"O in the same function.
315 .BR va_copy ()
316 ¤¬¼Â¹Ô¤µ¤ì¤ë¤´¤È¤Ë¡¢
317 Âбþ¤¹¤ë
318 .BR va_end ()
319 ¤òƱ¤¸´Ø¿ôÆâ¤Ç¼Â¹Ô¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
320 .\"O Some systems that do not supply
321 .\"O .BR va_copy ()
322 .\"O have
323 .\"O .B __va_copy
324 .\"O instead, since that was the name used in the draft proposal.
325 ¤³¤Î̾Á°¤Ï¤Þ¤À draft proposal ¤Ê¤Î¤Ç¡¢
326 .BR va_copy ()
327 ¤ÎÂå¤ï¤ê¤Ë
328 .B __va_copy
329 ¤òÍѤ¤¤ë¥·¥¹¥Æ¥à¤â¤¢¤ë¡£
330 .SH ½àµò
331 .BR va_start (),
332 .BR va_arg (),
333 .BR va_end ()
334 ¥Þ¥¯¥í¤Ï C89 ½àµò¤Ç¤¢¤ë¡£
335 .\"O C99 defines the
336 .\"O .BR va_copy ()
337 .\"O macro.
338 .BR va_copy ()
339 ¤Ï C99 ¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
340 .\"O .SH NOTES
341 .SH Ãí°Õ
342 .\"O These macros are
343 .\"O .I not
344 .\"O compatible with the historic macros they replace.
345 .\"O A backward compatible version can be found in the include file
346 .\"O .IR <varargs.h> .
347 ¤³¤ì¤é¤Î¥Þ¥¯¥í¤Ï¡¢°ÊÁ°¤«¤éÍѤ¤¤é¤ì¤Æ¤­¤¿Æ±Åù¤Î¥Þ¥¯¥í·²¤È
348 ¸ß´¹¤Ç¤Ï\fI¤Ê¤¤\fP¡£²áµî¤Î¤â¤Î¤È¸ß´¹¤Ê¥Ð¡¼¥¸¥ç¥ó¤Ï¡¢
349 ¥¤¥ó¥¯¥ë¡¼¥É¥Õ¥¡¥¤¥ë
350 .I <varargs.h>
351 ¤Ë¸ºß¤¹¤ë¡£
352 .PP
353 .\"O The historic setup is:
354 Îò»ËŪ¤Ê¥»¥Ã¥È¥¢¥Ã¥×¤Ï°Ê²¼¤Î¤È¤ª¤ê¤Ç¤¢¤ë¡£
355 .in +4n
356 .nf
357
358 #include <varargs.h>
359
360 void
361 foo(va_alist)
362     va_dcl
363 {
364     va_list ap;
365
366     va_start(ap);
367     while (...) {
368         ...
369         x = va_arg(ap, type);
370         ...
371     }
372     va_end(ap);
373 }
374
375 .fi
376 .in
377 .\"O On some systems,
378 .\"O .I va_end
379 .\"O contains a closing \(aq}\(aq matching a \(aq{\(aq in
380 .\"O .IR va_start ,
381 .\"O so that both macros must occur in the same function, and in a way
382 .\"O that allows this.
383 .I va_start
384 ¥Þ¥¯¥í¤Ë \(aq}\(aq ¤ò´Þ¤ß¡¢
385 .I va_end
386 ¥Þ¥¯¥í¤ËÂбþ¤¹¤ë \(aq{\(aq ¤ò´Þ¤à¥·¥¹¥Æ¥à¤â¤¢¤ë¤Î¤Ç¡¢
387 ¤³¤ÎÆó¤Ä¤Î¥Þ¥¯¥í¤ÏƱ¤¸´Ø¿ô¤Ë¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
388 .\"O .SH BUGS
389 .SH ¥Ð¥°
390 .\"O Unlike the
391 .\"O .B varargs
392 .\"O macros, the
393 .\"O .B stdarg
394 .\"O macros do not permit programmers to code a function with no fixed
395 .\"O arguments.
396 .\"O This problem generates work mainly when converting
397 .\"O .B varargs
398 .\"O code to
399 .\"O .B stdarg
400 .\"O code, but it also creates difficulties for variadic functions that wish to
401 .\"O pass all of their arguments on to a function that takes a
402 .\"O .I va_list
403 .\"O argument, such as
404 .\"O .BR vfprintf (3).
405 .B varargs
406 ¥Þ¥¯¥í¤È¤Ï°Û¤Ê¤ê¡¢
407 .B stdarg
408 ¥Þ¥¯¥í¤Ç¤Ï¸ÇÄê°ú¤­¿ô¤Ê¤·¤Ç´Ø¿ô¤ò»ØÄꤹ¤ë¤³¤È¤¬µö¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
409 ¤³¤ì¤Ï
410 .B varargs
411 ¥Ù¡¼¥¹¤Î¥³¡¼¥É¤ò
412 .B stdarg
413 ¤Î¥³¡¼¥É¤Ë½ñ¤­´¹¤¨¤ë¤È¤­¤Ë¡¢ÌÌÅݤʺî¶È¤Î¤â¤È¤Ë¤Ê¤ë¡£
414 ¤Þ¤¿¡¢¤¹¤Ù¤Æ¤Î°ú¤­¿ô¤ò
415 .I va_list
416 ¤È¤·¤Æ²ÄÊѸĻØÄꤷ¤¿¤¤¤è¤¦¤Ê¾ì¹ç
417 .RB ( vfprintf (3)
418 ¤Ê¤É) ¤Ë¤â¾ã³²¤È¤Ê¤ë¡£
419 .\"O .SH EXAMPLE
420 .SH Îã
421 ´Ø¿ô
422 .I foo
423 ¤Ï½ñ¼°Ê¸»ú¤«¤é¤Ê¤ëʸ»úÎó¤ò¼õ¤±Æþ¤ì¡¢¤½¤Î½ñ¼°Ê¸»ú¤ËÂбþ¤¹¤ë·¿¤Ç²ÄÊѸĤÎ
424 °ú¤­¿ô¤òÆɤ߹þ¤ß¡¢°õ»ú¤¹¤ë¡£
425 .nf
426
427 #include <stdio.h>
428 #include <stdarg.h>
429
430 void
431 foo(char *fmt, ...)
432 {
433     va_list ap;
434     int d;
435     char c, *s;
436
437     va_start(ap, fmt);
438     while (*fmt)
439         switch (*fmt++) {
440         case \(aqs\(aq:              /* string */
441             s = va_arg(ap, char *);
442             printf("string %s\en", s);
443             break;
444         case \(aqd\(aq:              /* int */
445             d = va_arg(ap, int);
446             printf("int %d\en", d);
447             break;
448         case \(aqc\(aq:              /* char */
449             /* need a cast here since va_arg only
450                takes fully promoted types */
451             c = (char) va_arg(ap, int);
452             printf("char %c\en", c);
453             break;
454         }
455     va_end(ap);
456 }
457 .fi