Espacios de nombres
Variantes
Acciones

va_arg

De cppreference.com
< cpp‎ | utility‎ | variadic

 
 
Utilidades de la biblioteca
Escriba apoyo (basic types, RTTI, type traits)
Gestión de memoria dinámica
Gestión de errores
Programa de servicios públicos
Funciones variadic
Fecha y hora
Objetos Function
initializer_list(C++11)
bitset
hash(C++11)
Operadores relacionales
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
Pares y tuplas
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pair
tuple(C++11)
piecewise_construct_t(C++11)
piecewise_construct(C++11)
Cambiar, hacia adelante y mover
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
swap
forward(C++11)
move(C++11)
move_if_noexcept(C++11)
declval(C++11)
 
 
Defined in header <cstdarg>
T va_arg(va_list ap, T);
La macro va_arg expande una expresión de T tipo que corresponde al siguiente parámetro de la va_list ap .
Original:
The va_arg macro expands to an expression of type T that corresponds to the next parameter from the va_list ap.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Antes de va_arg llamando, ap debe ser inicializado por una llamada a va_start o va_copy, sin una llamada a intervenir va_end. A cada invocación de la macro va_arg modifica ap para apuntar a la siguiente variable argumento .
Original:
Prior to calling va_arg, ap must be initialized by a call to either va_start or va_copy, with no intervening call to va_end. Each invocation of the va_arg macro modifies ap to point to the next variable argument.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Si va_arg se llama cuando no hay argumentos más en ap, o si el tipo del siguiente argumento en ap (después de las promociones) no es compatible con T, el comportamiento es indefinido, a menos que:
Original:
If va_arg is called when there are no more arguments in ap, or if the type of the next argument in ap (after promotions) is not compatible with T, the behavior is undefined, unless:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • un tipo es un tipo entero con signo, el otro tipo es el correspondiente tipo entero sin signo, y el valor es representable en ambos tipos, o
    Original:
    one type is a signed integer type, the other type is the corresponding unsigned integer type, and the value is representable in both types; or
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • un tipo es un puntero a void y el otro es un puntero a un tipo de carácter .
    Original:
    one type is pointer to void and the other is a pointer to a character type.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

Contenido

[editar] Parámetros

ap -
una instancia del tipo de va_list
Original:
an instance of the va_list type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
T -
el tipo del siguiente parámetro de ap
Original:
the type of the next parameter in ap
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Ampliado valor

el siguiente parámetro variable en ap
Original:
the next variable parameter in ap
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Ejemplo

#include <iostream>
#include <cstdarg>
#include <cmath>
 
double stddev(int count, ...) 
{
    double sum = 0;
    double sum_sq = 0;
    va_list args;
    va_start(args, count);
    for (int i = 0; i < count; ++i) {
        double num = va_arg(args, double);
        sum += num;
        sum_sq += num*num;
    }
    return std::sqrt(sum_sq/count - (sum/count)*(sum/count));
}
 
int main() 
{
    std::cout << stddev(4, 25.0, 27.3, 26.9, 25.7) << '\n';
}

Output:

0.920258

[editar] Ver también

permite el acceso a los argumentos de la función variadic
Original:
enables access to variadic function arguments
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función macro) [edit]
(C++11)
makes a copy of the variadic function arguments
(función macro) [edit]
termina recorrido de los argumentos de la función variadic
Original:
ends traversal of the variadic function arguments
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función macro) [edit]