Espaces de noms
Variantes
Affichages
Actions

va_start

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

Defined in header <cstdarg>
void va_start(va_list ap, parm_n);
La macro va_start permet d'accéder aux arguments variables suivant l'argument nommé parm_n .
Original:
The va_start macro enables access to the variable arguments following the named argument parm_n.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
va_start doit être appelée avec une instance à un objet valide va_list ap avant tout appel à va_arg .
Original:
va_start should be invoked with an instance to a valid va_list object ap before any calls to va_arg.
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.
parm_n -
le paramètre nommé précédant le premier paramètre variable
Original:
the named parameter preceding the first variable parameter
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

(Aucun)
Original:
(none)
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>
 
int add_nums(int count, ...) 
{
    int result = 0;
    va_list args;
    va_start(args, count);
    for (int i = 0; i < count; ++i) {
        result += va_arg(args, int);
    }
    return result;
}
 
int main() 
{
    std::cout << add_nums(4, 25, 25, 50, 50) << '\n';
}

Résultat :

150

[modifier] Voir aussi

accède à l'argument de la fonction suivante variadique
Original:
accesses the next variadic function argument
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]