When using va_start(), va_arg() and va_end() to read parameters passed to a method, is there a way to count how many arguments there are?
According to the man page i
There are two ways to know how many arguments were passed. First, you can have one of the function parameters tell you (like printf
for example). The other way is to have a sentinel value at the end of your list - for instance, you could stop at a NULL
argument.
You can use va_copy
if you choose the second method, but still want to count the parameters before deciding what to do with them.