va_arg
De cppreference.com
![]() |
Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate.
La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí. |
Definido en el archivo de encabezado <cstdarg>
|
||
T va_arg(va_list ap, T); |
||
La macro
va_arg
expande una expresión de tipo T
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.
You can help to correct and verify the translation. Click here for instructions.
Antes de llamar a
va_arg
, ap
debe ser inicializado por una llamada a va_start o va_copy, sin una llamada intermedia a va_end. En cada invocación de la macro va_arg
modifica ap
para apuntar al siguiente argumento variable.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.
You can help to correct and verify the translation. Click here for instructions.
Si
va_arg
se llama cuando no hay más argumentos 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.
You can help to correct and verify the translation. Click here for instructions.
- un tipo sea un tipo entero con signo, el otro tipo sea el correspondiente tipo entero sin signo, y el valor sea representable en ambos tipos, oOriginal:one type is a signed integer type, the other type is the corresponding unsigned integer type, and the value is representable in both types; orThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - un tipo sea un puntero a void y el otro sea 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.
You can help to correct and verify the translation. Click here for instructions.
[editar] Ejemplo
Ejecuta este código
#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'; }
Salida:
0.920258
[editar] Ver también
Permite el acceso a los argumentos de función variádica. (macro de función) | |
(C++11) |
Crea una copia de los argumentos de función variádica. (macro de función) |
Termina el recorrido de los argumentos de función variádica. (macro de función) |