A variadic macro is a feature of C preprocessor to accept varying number of arguments to a macro.

The declaration syntax is similar to that of variadic functions: an ellipsis "..." is used to indicate that one or more arguments must be passed. Common compilers also permit passing zero arguments to such a macro, however. During macro expansion each occurrence of the special identifier __VA_ARGS__ in the macro replacement list is replaced by the passed arguments. No means is provided to access individual arguments in the variable argument list, nor to find out how many were passed. However, macros can be written to count the number of arguments that have been passed.

#define <macro name>() macro body>
#define <macro name>() < another variadic macro/function(__VA_ARGS__)>

Example -
#define dbgprintf(...)  fprintf (stderr, __VA_ARGS__)

int main (int argc, char * argv[])
#ifdef DEBUG
dbgprintf("Running debug version file:%s :\n", __FILE__, __LINE__); 


About our authors: Team EQA

You have viewed 1 page out of 252. Your C learning is 0.00% complete. Login to check your learning progress.