.\" -*- coding: UTF-8 -*- .\" 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. .\" .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB) .\" 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. .\" %%%LICENSE_END .\" .\" @(#)stdarg.3 6.8 (Berkeley) 6/29/91 .\" .\" Converted for Linux, Mon Nov 29 15:11:11 1993, faith@cs.unc.edu .\" Additions, 2001-10-14, aeb .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH STDARG 3 "1 Noviembre 2020" "" "Manual del Programador de Linux" .SH NOMBRE stdarg, va_start, va_arg, va_end, va_copy \- lista de argumentos variable .SH SINOPSIS \fB#include \fP .PP \fBvoid va_start(va_list \fP\fIap\fP\fB, \fP\fIlast\fP\fB);\fP .br \fItype\fP\fB va_arg(va_list \fP\fIap\fP\fB, \fP\fItype\fP\fB);\fP .br \fBvoid va_end(va_list \fP\fIap\fP\fB);\fP .br \fBvoid va_copy(va_list \fP\fIdest\fP\fB, va_list \fP\fIsrc\fP\fB);\fP .SH DESCRIPCIÓN Una función podría ser llamada con un número de argumentos variable de tipos igualmente variables. El fichero de cabecera (include) \fI\fP declara un tipo \fIva_list\fP y define tres macros para moverse a través de una lista de argumentos cuyo número y tipo no son conocidos para la función llamada. .PP Dicha función debe declarar un objeto de tipo \fIva_list\fP el cual es utilizado por las macros \fBva_start\fP(), \fBva_arg\fP() y \fBva_end\fP(). .SS va_start() La macro \fBva_start\fP() inicializa \fIap\fP para su uso posterior por \fBva_arg\fP() y \fBva_end\fP(), y debe ser llamada en primer lugar. .PP The argument \fIlast\fP is the name of the last argument before the variable argument list, that is, the last argument of which the calling function knows the type. .PP Because the address of this argument may be used in the \fBva_start\fP() macro, it should not be declared as a register variable, or as a function or an array type. .SS va_arg() The \fBva_arg\fP() macro expands to an expression that has the type and value of the next argument in the call. The argument \fIap\fP is the \fIva_list\fP \fIap\fP initialized by \fBva_start\fP(). Each call to \fBva_arg\fP() modifies \fIap\fP so that the next call returns the next argument. The argument \fItype\fP is a type name specified so that the type of a pointer to an object that has the specified type can be obtained simply by adding a * to \fItype\fP. .PP El primer uso de la macro \fBva_arg\fP() despues de \fBva_start\fP() devuelve el argumento tras \fIlast\fP. Invocaciones sucesivas devolverán los valores del resto de los argumentos. .PP Si no hay próximo argumento, o si \fItype\fP no es compatible con el tipo del próximo argumento, se producirán errores impredecibles. .PP Si \fIap\fP es pasado a una función que usa \fBva_arg(\fP\fIap\fP\fB,\fP\fItype\fP\fB),\fP el valor de \fIap\fP es indefinido al regresar dicha función. .SS va_end() A cada invocación de \fBva_start\fP() le corresponde una invocación de \fBva_end\fP() en la misma función. Después de la llamada a \fBva_end(\fP\fIap\fP\fB)\fP la variable \fIap\fP es indefinida. Son posibles varios recorridos de la lista, cada uno comprendido entre \fBva_start\fP() y \fBva_end\fP(). \fBva_end\fP() puede ser una macro o una función. .SS va_copy() The \fBva_copy\fP() macro copies the (previously initialized) variable argument list \fIsrc\fP to \fIdest\fP. The behavior is as if \fBva_start\fP() were applied to \fIdest\fP with the same \fIlast\fP argument, followed by the same number of \fBva_arg\fP() invocations that was used to reach the current state of \fIsrc\fP. .PP .\" Proposal from clive@demon.net, 1997-02-28 Una implementación obvia haría que \fIva_list\fP fuera un puntero al marco de pila de la función. En tal caso (con mucho el más común) no hay ningún problema con una asignación del tipo .PP .in +4n .EX va_list aq = ap; .EE .in .PP Desafortunadamente, también hay sistemas que lo implementan como un array de punteros (de longitud 1), y por tanto es necesario .PP .in +4n .EX va_list aq; *aq = *ap; .EE .in .PP Finally, on systems where arguments are passed in registers, it may be necessary for \fBva_start\fP() to allocate memory, store the arguments there, and also an indication of which argument is next, so that \fBva_arg\fP() can step through the list. Now \fBva_end\fP() can free the allocated memory again. To accommodate this situation, C99 adds a macro \fBva_copy\fP(), so that the above assignment can be replaced by .PP .in +4n .EX va_list aq; va_copy(aq, ap); \&... va_end(aq); .EE .in .PP A cada invocación de \fBva_copy\fP() le corresponde una invocación de \fBva_end\fP() en la misma función. Algunos sistemas que no proporcionan \fBva_copy\fP() tienen \fB__va_copy\fP() en su lugar, puesto que ese fue el nombre usado en la propuesta inicial. .SH ATRIBUTOS Para obtener una explicación de los términos usados en esta sección, véase \fBattributes\fP(7). .TS allbox; lbw21 lb lb l l l. Interfaz Atributo Valor T{ \fBva_start\fP(), \fBva_end\fP(), \fBva_copy\fP() T} Seguridad del hilo Multi\-hilo seguro T{ \fBva_arg\fP() T} Seguridad del hilo MT\-Safe race:ap .TE .SH "CONFORME A" Las macros \fBva_start\fP(), \fBva_arg\fP() y \fBva_end\fP() concuerdan con C89. C99 define la macro \fBva_copy\fP(). .SH ERRORES Unlike the historical \fBvarargs\fP macros, the \fBstdarg\fP macros do not permit programmers to code a function with no fixed arguments. This problem generates work mainly when converting \fBvarargs\fP code to \fBstdarg\fP code, but it also creates difficulties for variadic functions that wish to pass all of their arguments on to a function that takes a \fIva_list\fP argument, such as \fBvfprintf\fP(3). .SH EJEMPLOS La función \fIfoo\fP toma una cadena de caracteres de formato e imprime el argumento asociado con cada caracter de formato basado en el tipo. .PP .EX #include #include void foo(char *fmt, ...) /* \(aq...\(aq is C syntax for a variadic function */ { va_list ap; int d; char c; char *s; va_start(ap, fmt); while (*fmt) switch (*fmt++) { case \(aqs\(aq: /* string */ s = va_arg(ap, char *); printf("string %s\en", s); break; case \(aqd\(aq: /* int */ d = va_arg(ap, int); printf("int %d\en", d); break; case \(aqc\(aq: /* char */ /* need a cast here since va_arg only takes fully promoted types */ c = (char) va_arg(ap, int); printf("char %c\en", c); break; } va_end(ap); } .EE .SH "VÉASE TAMBIÉN" \fBvprintf\fP(3), \fBvscanf\fP(3), \fBvsyslog\fP(3) .SH COLOFÓN Esta página es parte de la versión 5.10 del proyecto Linux \fIman\-pages\fP. Puede encontrar una descripción del proyecto, información sobre cómo informar errores y la última versión de esta página en \%https://www.kernel.org/doc/man\-pages/. .SH TRADUCCIÓN La traducción al español de esta página del manual fue creada por Juan Piernas y Miguel Pérez Ibars . Esta traducción es documentación libre; lea la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 .UE o posterior con respecto a las condiciones de copyright. No existe NINGUNA RESPONSABILIDAD. Si encuentra algún error en la traducción de esta página del manual, envíe un correo electrónico a .MT debian-l10n-spanish@lists.debian.org>. .ME .