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.

Syntax:
#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__); 
#endif

}

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

 Vote 0

Similar topics related to this section

factorial using recursion, Fibonaci using recursion, Armstrong number, variadic functions, variadic macro, multiple arguments in printf and scanf, strcpy and strcat source, memcpy vs memmove,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan