Count number of parameters in C variable argument method call
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 if you call va_arg() too many times you get "random errors": If there is no next argument, or if type is not compatible with the type of the actual next argument (as promoted according to the default argument promotions), random errors will occur. No. a Variable Argument function (such as printf ), must "know" when to stop looking for more arguments. printf knows by the number of %d , %s and other symbols in its format string. Other