Espaces de noms
Variantes
Affichages
Actions

va_arg

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

Defined in header <cstdarg>
T va_arg(va_list ap, T);
La macro va_arg développe en une expression de T type qui correspond au paramètre suivant 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.
Avant d'appeler va_arg, ap doit être initialisé par un appel à va_start soit ou va_copy, sans appel d'intervenir pour va_end. Chaque invocation de la macro modifie va_arg ap pour pointer vers le prochain argument 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.
Si va_arg est appelé quand il ya des arguments ne contient plus ap, ou si le type de l'argument suivant dans ap (après les promotions) n'est pas compatible avec T, le comportement est indéfini, à moins 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 type est un type entier signé, l'autre type est le correspondant de type entier non signé, et la valeur est représentable dans les deux types, ou
    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 type pointeur est à void et l'autre est un pointeur sur un type de caractère .
    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.

Sommaire

[modifier] Paramètres

ap -
une instance du type 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 -
le type du paramètre suivant dans 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.

[modifier] Élargi valeur

le paramètre suivant dans la variable 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.

[modifier] Exemple

#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';
}

Résultat :

0.920258

[modifier] Voir aussi

permet d'accéder aux arguments de la fonction variadique
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.

(fonction macro) [edit]
(C++11)
fait une copie des arguments de la fonction variadique
Original:
makes a copy 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.

(fonction macro) [edit]
termine la traversée des arguments de la fonction variadique
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.

(fonction macro) [edit]