Reputation: 5369
Here is the example of varargs
.
I'm a little puzzled.
va_list ap;
va_arg (ap + (n-1), int); // **INCORRECT USAGE**
Is it correct? If not, how to get the nth argument?
ap
increase?It says ap
will increase to the next argument, but if I use va_arg(ap + (n-1), int), n>=2
, will ap
increase?
Sometimes, we declared Cnt
abbreviated from Count
or Counter
.
What's ap
abbreviated from?
ap
?I know it's va_list
type, but what is va_list
? struct? int? or something else?
Thanks.
Upvotes: 1
Views: 336
Reputation: 5301
If you want the n-th argument you will have to call va_arg()
with correct type n-1 times.
Your examples 1 and 2 are wrong. ap
will be changed by va_arg()
automatically.
Type of va_list
is implementation defined, but is usually a char*
.
Upvotes: 6