va_arg
Da cppreference.com.
|
|
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
<metanoindex/>
<tbody> </tbody>| Elemento definito nell'header <cstdarg>
|
||
T va_arg(va_list ap, T); |
||
La macro
va_arg espande un'espressione di T tipo che corrisponde al parametro successivo dal 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.
Prima di chiamare
va_arg, ap deve essere inizializzato da una chiamata a uno o va_start va_copy, con nessuna chiamata intervenire per va_end. Ogni invocazione della macro va_arg modifica ap per puntare al prossimo argomento variabile.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 viene chiamato quando non ci sono argomenti non più in ap, o se il tipo di argomento successivo in ap (dopo la promozione) non è compatibile con T, il comportamento è indefinito, a meno che: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 è un tipo intero con segno, l'altro tipo è il corrispondente tipo intero senza segno, e il valore è rappresentabile in entrambi i tipi, 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 puntatore
voide l'altro è un puntatore a un tipo di carattere.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.
Parametri
| ap | - | un'istanza del 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 | - | il tipo di parametro successivo in
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. |
Expanded valore
il successivo parametro variabile in
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.
Esempio
#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
Vedi anche
consente l'accesso agli argomenti della funzione 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. (funzione macro) | |
(C++11) |
makes a copy of the variadic function arguments (funzione macro) |
termina attraversamento degli argomenti della funzione 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. (funzione macro) | |