Reputation: 1129
This is the implementation for the va_start
macro:
#define va_start(list, param) (list = (((va_list)¶m) + sizeof(param)))
As you can see, the va_start
macro is returning the address of the first byte in the variable list of arguments by assuming that it exists directly after the count
parameter (I mean by the count
parameter the name of a parameter that I declare that I will pass to the number of arguments).
So if I am using in addition to the count
parameter other parameters, Should the count
parameter be declared directly before the ellipsis (...)?
Upvotes: 0
Views: 73
Reputation: 53016
va_start()
should always be called with the last named parameter, so for example
void function(int x, int y, int z, ...)
{
va_list ap;
va_start(ap, z);
.
.
.
va_end(ap);
}
So if I am using in addition to the count parameter other parameters, Should the count parameter be declared directly before the ellipsis (...)?
Yes, if you want to use va_start()
this way
va_list ap;
va_start(ap, count);
Upvotes: 1