Namensräume
Varianten
Aktionen

va_start

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

Defined in header <cstdarg>
void va_start(va_list ap, parm_n);
Die va_start Makro ermöglicht den Zugriff auf die variable Argumente nach dem benanntes Argument 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 sollte mit einer Instanz zu einem gültigen va_list Objekt aufgerufen werden ap vor allen Aufrufen 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.

Inhaltsverzeichnis

[Bearbeiten] Parameter

ap -
eine Instanz der va_list Typ
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 -
die benannten Parameter vor der ersten variablen Parameter
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.

[Bearbeiten] Expanded Wert

(None)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Beispiel

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

Output:

150

[Bearbeiten] Siehe auch

greift auf die nächsten variadische Funktionsargument
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.

(funktionieren Makro) [edit]
endet Durchlaufen der variadische Funktionsargumente
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.

(funktionieren Makro) [edit]