CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Wed, 30 Jul 2025 10:26:20 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/cstdarg/va_arg/
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 30 Jul 2025 10:26:20 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"66e7-bWA4Sh/KijUU0ELyJ+fqpu/mrco"
Content-Encoding: gzip
This macro expands to an expression of type type with the value of the current argument in the variable arguments list identified by ap.
Each call to this macro modifies the state of ap so that the next call to this macro will expand to the argument that follows the one it evaluates to.
Notice that va_arg cannot determine the actual type of the argument passed to the function, but uses whatever type is passed as the type macro argument as its type.
Notice also that va_arg does not determine either whether the retrieved argument is the last argument passed to the function (or even if it is an element past the end of that list). The function should be designed in such a way that the number of parameters can be inferred in some way by the values of either the named parameters or the additional arguments already read.
This FindMax function takes as its first parameter the number of additional arguments it is going to get. The first additional argument is retrieved and used as an initial reference for comparison, and then the remaining additional arguments are retrieved in a loop and compared to return the greatest one (which in this case is
Output:
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
macro
<cstdarg>
va_arg
type va_arg (va_list ap, type)
Retrieve next argument
Each call to this macro modifies the state of ap so that the next call to this macro will expand to the argument that follows the one it evaluates to.
Notice that va_arg cannot determine the actual type of the argument passed to the function, but uses whatever type is passed as the type macro argument as its type.
Notice also that va_arg does not determine either whether the retrieved argument is the last argument passed to the function (or even if it is an element past the end of that list). The function should be designed in such a way that the number of parameters can be inferred in some way by the values of either the named parameters or the additional arguments already read.
Parameters
- ap
- Object of type va_list carrying information about the current retrieval state of a variable argument list. This object shall have been initialized by an initial call to va_start or va_copy and not have been released with va_end.
- type
- A type name. This type name is used as the type of the expression this macro expands to (i.e., its return type).
For a type expression to be suitable for its use with va_arg, it must be such thattype*
produces a pointer to type.
The type shall be compatible with type of the extracted argument (as promoted according to the default argument promotions), or one be the unsigned version of the other, or one be a void pointer and the other some other pointer type.
Return Value
Returns the current additional argument as an expression of type type.Example
|
|
This FindMax function takes as its first parameter the number of additional arguments it is going to get. The first additional argument is retrieved and used as an initial reference for comparison, and then the remaining additional arguments are retrieved in a loop and compared to return the greatest one (which in this case is
892
).Output:
The largest value is: 892 |
See also
- va_start
- Initialize a variable argument list (macro)
- va_end
- End using variable argument list (macro)
- va_list
- Type to hold information about variable arguments (type)
- vsprintf
- Write formatted data from variable argument list to string (function)
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us