Mawg
Mawg

Reputation: 40140

Variadic function - how to get number of var_args?

Can this be done at all? Is there, for example, some sort of va_num_args?

Basically, I am logging events across a serial port in a prinf() like manner, taking a format string and, optional ly, some arguments. I would like to know if there are any such option arguments present.

E.g, can I distinguish between Trace("No paramters here"); and Trace("forty two = %d", 43 - 1); ?

Upvotes: 1

Views: 139

Answers (1)

makes
makes

Reputation: 6538

No, but the following methods can be used instead:

  • Deduce argument cound from a format string (like printf).
  • Use a sentinel value to indicate last argument.
  • Supply a dedicated count argument.

Upvotes: 5

Related Questions