File: stdarg.3

package info (click to toggle)
manpages-es 1.24a-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,256 kB
  • ctags: 7
  • sloc: makefile: 66; sh: 62
file content (196 lines) | stat: -rw-r--r-- 5,727 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
.\" Copyright (c) 1990, 1991 The Regents of the University of California.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" the American National Standards Committee X3, on Information
.\" Processing Systems.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"	This product includes software developed by the University of
.\"	California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"	@(#)stdarg.3	6.8 (Berkeley) 6/29/91
.\"
.\" Converted for Linux, Mon Nov 29 15:11:11 1993, faith@cs.unc.edu
.\"
.TH STDARG 3  "29 Noviembre 1993" "BSD MANPAGE" "Manual del Programador de Linux"
.SH NOMBRE
stdarg \- lista de argumentos variable
.SH SINPSIS
.B #include <stdarg.h>
.sp
.BI "void va_start( va_list " ap ", " last );
.br
.BI "" type " va_arg( va_list " ap ", " type );
.br
.BI "void va_end( va_list " ap );
.SH DESCRIPCIN
Una funcin podra ser llamada con un nmero de argumentos variable de tipos
igualmente variables. El archivo de cabecera (include)
.I stdarg.h
declara un tipo
.B va_list
y define tres macros para moverse a traves de una lista de argumentos cuyo
nmero y tipo no son conocidos para la funcin llamada.
.PP
Dicha funcin debe declarar un objeto de tipo
.B va_list
el cual es utilizado por las macros
.BR va_start ,
.BR va_arg ,
y
.BR va_end .
.PP
La macro
.B va_start
inicializa
.I ap
para su uso posterior por
.B va_arg
y
.BR va_end ,
y debe ser llamada en primer lugar.
.PP
El parmetro
.I last
es el nombre del ltimo parmetro antes de la lista de argumentos variables,
es decir, el ltimo parametro sobre el cual la funcin llamada conoce el
tipo.
.PP
Dado que la direccin de este parmetro es utilizada por la macro
.B va_start
no debera ser declarado como una variable de registro, como una funcin ni
como un array.
.PP
La macro
.B va_start
no devuelve valor alguno.
.PP
La macro
.B va_arg
expande una expresin que contiene el tipo y el valor del prximo argumento
empleado en la llamada. El parmetro
.I ap
es el 
.BI va_list " " ap
inicializado por
.BR va_start .
Cada llamada a
.B va_arg
modifica
.I ap
por tanto la siguiente llamada devolver el prximo argumento. El parmetro
.I type
es el nombre de un tipo especificado para que para que el tipo de un puntero
a un objeto que es de dicho tipo pueda ser obtenido simplemente aadiendo un
* a
.IR type .
.PP
Si no hay prximo argumento, o si
.I type
no es compatible con el tipo del prximo argumento, se producieran errores
impredecibles.
.PP
El primer uso de la macro
.B va_arg
despues de
.B va_start
devuelve el argumento tras
.IR last .
Invocaciones sucesivas devolvern los valores del resto de los argumentos.
.PP
La macro
.B va_end
manipula un retorno normal de la funcin cuya lista de argumentos variable
fue inicializada por 
.BR va_start .
.PP
La macro
.B va_end
no devuelve valor alguno.
.SH EJEMPLOS
La funcin
.I foo
toma una cadena de caracteres de formato e imprime el argumento asociado
con cada caracter de formato basado en el tipo.
.RS
.nf
void foo(char *fmt, ...)
{
	va_list ap;
	int d;
	char c, *p, *s;

	va_start(ap, fmt);
	while (*fmt)
		switch(*fmt++) {
		case 's':			/* string */
			s = va_arg(ap, char *);
			printf("string %s\en", s);
			break;
		case 'd':			/* int */
			d = va_arg(ap, int);
			printf("int %d\en", d);
			break;
		case 'c':			/* char */
			c = va_arg(ap, char);
			printf("char %c\en", c);
			break;
		}
	va_end(ap);
}
.fi
.RE
.SH CONFORME A
Las macros
.BR va_start ,
.BR va_arg ,
y
.B va_end
concuerdan con ANSI C3.159-1989 (``ANSI C'').
.SH COMPATIBILIDAD
Estas macros
.I no
son compatibles con las macros histricas que reemplazan. Se puede encontrar
una versin compatible "hacia atrs" en el fichero de cabecera
.IR varargs.h .
.SH ERRORES
Al contrario que las macros
.B varargs
, las macros
.B stdarg
no permiten a los programadores codificar una funcin con argumentos
variables. Este problema genera trabajo principalmente cuando se convierte
cdigo basado en
.B varargs
a
.B stdarg
pero adems crea dificultades a las funciones que quieran pasar todos sus
argumentos en una funcin que toma una lista de argumentos
.B va_list
, como
.BR vfprintf (3).