What is the return value of va_arg in empty lists?

207 views Asked by At

In case of using variable arguments in cpp, what does va_arg return as the next value in case there is no next value?

Also, can this be considered as a solution for counting the elements in va_list?

1

There are 1 answers

1
MSalters On BEST ANSWER

It's Undefined Behavior to do this, so you can't say anything about it. It's certainly unsuitable for counting.

Use variadic templates instead, those allow you to count arguments.