.\" -*- coding: UTF-8 -*- '\" t .\" 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. .\" .\" SPDX-License-Identifier: BSD-4-Clause-UC .\" .\" @(#)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 "5 Febrero 2023" "Páginas de manual de Linux 6.03" .SH NOMBRE stdarg, va_start, va_arg, va_end, va_copy \- lista de argumentos variable .SH BIBLIOTECA Biblioteca Estándar C (\fIlibc\fP, \fI\-lc\fP) .SH SINOPSIS .nf \fB#include \fP .PP \fBvoid va_start(va_list \fP\fIap\fP\fB, \fP\fIlast\fP\fB);\fP \fItype\fP\fB va_arg(va_list \fP\fIap\fP\fB, \fP\fItype\fP\fB);\fP \fBvoid va_end(va_list \fP\fIap\fP\fB);\fP \fBvoid va_copy(va_list \fP\fIdest\fP\fB, va_list \fP\fIsrc\fP\fB);\fP .fi .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). .ad l .nh .TS allbox; lbx 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 .hy .ad .sp 1 .SH ESTÁNDARES C99. .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 carácter 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 \[aq]s\[aq]: /* string */ s = va_arg(ap, char *); printf("string %s\en", s); break; case \[aq]d\[aq]: /* int */ d = va_arg(ap, int); printf("int %d\en", d); break; case \[aq]c\[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) .PP .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 . .PP 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. .PP 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 .