va_arg
De cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody>| Definido no cabeçalho <cstdarg>
|
||
T va_arg(va_list ap, T); |
||
A macro
va_arg expande para uma expressão de T tipo que corresponde ao parâmetro seguinte do 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
va_arg chamando, ap deve ser inicializado através de uma chamada para qualquer va_start ou va_copy, com nenhuma chamada a intervir para va_end. Cada invocação do macro va_arg modifica ap para apontar para o próximo argumento variável.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.
Se
va_arg é chamado quando há argumentos não mais em ap, ou se o tipo do próximo argumento em ap (depois de promoções) não é compatível com T, o comportamento é 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.
- Um tipo é um tipo inteiro assinado, o outro tipo é o tipo sem sinal correspondente número inteiro, e o valor é representável em ambos os tipos, ouOriginal: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. - é um tipo de ponteiro para
voide o outro é um apontador para um tipo de caracteres.Original:one type is pointer tovoidand 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.
Parâmetros
| ap | - | uma instância do tipo 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 | - | o tipo do parâmetro seguinte na
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. |
Expandiu valor
o próximo parâmetro variável em
apOriginal:
the next variable parameter in
apThe 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.
Exemplo
#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';
}
Saída:
0.920258
Veja também
permite o acesso a argumentos de função variádicos 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. (função macro) | |
(C++11) |
makes a copy of the variadic function arguments (função macro) |
termina travessia dos argumentos da função variádicos 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. (função macro) |