1

I have a use case where i need the count of arguments passed to variadic macro in c. I tried using the following code:

#define COUNT_ARGS(...) COUNT_ARGS_(,##__VA_ARGS__,9,8,7,6,5,4,3,2,1,0)
#define COUNT_ARGS_(z,a,b,c,d,e,f,g,h,i,cnt,...) cnt

But this has a serious issue, if user passes say 11 arguments to this maro the count is returned as value of 11th argument.

Is there any other way i can get the count of arguments passed.

  • 5
    possible duplicate of [C++ preprocessor \_\_VA\_ARGS\_\_ number of arguments](http://stackoverflow.com/questions/2124339/c-preprocessor-va-args-number-of-arguments) – ocirocir May 12 '15 at 22:02
  • As mentioned the solution proposed has an issue, what user passes more that 63 arguments as suggested in the post, the count comes out to be value of 64 argument – user2486532 May 12 '15 at 23:16
  • Have you check this solution http://stackoverflow.com/a/2124433/835146 ? – ocirocir May 13 '15 at 05:34

0 Answers0