Count number of parameters in C variable argument method call

前端 未结 3 527
南笙
南笙 2021-01-12 16:53

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

3条回答
  •  Happy的楠姐
    2021-01-12 17:05

    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.

提交回复
热议问题