Penguin
Annotated edit history of stdarg(3) version 1, including all changes. View license author blame.
Rev Author # Line
1 perry 1 STDARG
2 !!!STDARG
3 NAME
4 SYNOPSIS
5 DESCRIPTION
6 EXAMPLES
7 CONFORMING TO
8 COMPATIBILITY
9 BUGS
10 ----
11 !!NAME
12
13
14 stdarg - variable argument lists
15 !!SYNOPSIS
16
17
18 __#include __
19
20
21 __void va_start( va_list__ ''ap''__,__
22 ''last''__);__''
23 type'' __va_arg( va_list__ ''ap''__,__
24 ''type''__);
25 void va_end( va_list__ ''ap''__);__
26 !!DESCRIPTION
27
28
29 A function may be called with a varying number of arguments
30 of varying types. The include file ''stdarg.h'' declares
31 a type __va_list__ and defines three macros for stepping
32 through a list of arguments whose number and types are not
33 known to the called function.
34
35
36 The called function must declare an object of type
37 __va_list__ which is used by the macros __va_start__,
38 __va_arg__, and __va_end__.
39
40
41 The __va_start__ macro initializes ''ap'' for
42 subsequent use by __va_arg__ and __va_end__, and must
43 be called first.
44
45
46 The parameter ''last'' is the name of the last parameter
47 before the variable argument list, i.e., the last parameter
48 of which the calling function knows the type.
49
50
51 Because the address of this parameter is used in the
52 __va_start__ macro, it should not be declared as a
53 register variable, or as a function or an array
54 type.
55
56
57 The __va_start__ macro returns no value.
58
59
60 The __va_arg__ macro expands to an expression that has
61 the type and value of the next argument in the call. The
62 parameter ''ap'' is the __va_list ap__ initialized by
63 __va_start__. Each call to __va_arg__ modifies
64 ''ap'' so that the next call returns the next argument.
65 The parameter ''type'' is a type name specified so that
66 the type of a pointer to an object that has the specified
67 type can be obtained simply by adding a * to
68 ''type''.
69
70
71 If there is no next argument, or if ''type'' is not
72 compatible with the type of the actual next argument (as
73 promoted according to the default argument promotions),
74 random errors will occur.
75
76
77 The first use of the __va_arg__ macro after that of the
78 __va_start__ macro returns the argument after
79 ''last''. Successive invocations return the values of the
80 remaining arguments.
81
82
83 The __va_end__ macro handles a normal return from the
84 function whose variable argument list was initialized by
85 __va_start__.
86
87
88 The __va_end__ macro returns no value.
89 !!EXAMPLES
90
91
92 The function ''foo'' takes a string of format characters
93 and prints out the argument associated with each format
94 character based on the type.
95
96
97 void foo(char *fmt, ...)
98 {
99 va_list ap;
100 int d;
101 char c, *p, *s;
102 va_start(ap, fmt);
103 while (*fmt)
104 switch(*fmt++) {
105 case 's': /* string */
106 s = va_arg(ap, char *);
107 printf(
108 !!CONFORMING TO
109
110
111 The __va_start__, __va_arg__, and __va_end__ macros
112 conform to ANSI X3.159-1989 (``ANSI C'').
113 !!COMPATIBILITY
114
115
116 These macros are ''not'' compatible with the historic
117 macros they replace. A backward compatible version can be
118 found in the include file ''varargs.h''.
119 !!BUGS
120
121
122 Unlike the __varargs__ macros, the __stdarg__ macros
123 do not permit programmers to code a function with no fixed
124 arguments. This problem generates work mainly when
125 converting __varargs__ code to __stdarg__ code, but it
126 also creates difficulties for variadic functions that wish
127 to pass all of their arguments on to a function that takes a
128 __va_list__ argument, such as
129 vfprintf(3).
130 ----
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.