Is there a standard C/C++ function that, given a printf
format string, returns the number of arguments it expects? E.g.:
num_printf_args("%d %s") == 2;
num_printf_args("%.1f%%") == 1;
num_printf_args("%*d") == 2;
Just counting the number of %
in the format string would be a first approximation, which works in the first example, but obviously not in the second and third ones.
I know gcc can do this, since at compile time it complains when the number of arguments (and also their type) actually passed to printf
does not match the format string.