va_arg
Aus 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>| definiert in Header <cstdarg>
|
||
T va_arg(va_list ap, T); |
||
Die
va_arg Makro auf einen Ausdruck vom Typ T, die dem nächsten Parameter entspricht der 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.
Vor dem Aufruf
va_arg muss ap durch einen Aufruf entweder va_start oder va_copy initialisiert werden, ohne dazwischen Aufruf va_end. Jeder Aufruf des va_arg Makro verändert ap, um zum nächsten variable Argument verweisen .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.
Wenn
va_arg wird aufgerufen, wenn es keine weiteren Argumente ap sind, oder wenn der Typ des nächsten Arguments in ap (nach Aktionen) ist nicht kompatibel mit T, ist das Verhalten undefiniert, es sei dennOriginal:
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.
- ein Typ ist eine signierte Integer-Typ, ist die andere Art der entsprechenden unsigned Integer-Typ, und der Wert darstellbar ist bei beiden Typen, oderOriginal: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. - ein Typ ist Zeiger auf
voidund das andere ist ein Zeiger auf einen Zeichentyp .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.
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. |
| T | - | der Typ der nächste Parameter 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 Wert
die nächste Variable Parameter 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.
Beispiel
#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
Siehe auch
ermöglicht den Zugriff auf variadische Funktionsargumente 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. (funktionieren Makro) | |
(C++11) |
makes a copy of the variadic function arguments (funktionieren Makro) |
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) | |