Possible Duplicate:
C/C++: How to make a variadic macro (variable number of arguments)
Just wondering if this is at all possible., so instead of how im currently handling logging and messages with multiple parameters im having to have a number of different macros for each case such as:
#define MSG( msg )
#define MSG1( fmt, arg1 )
#define MSG2( fmt, arg1, arg2 )
#define MSG3( fmt, arg1, arg2, arg3 )
#define MSG4( fmt, arg1, arg2, arg3, arg4 )
#define MSG5( fmt, arg1, arg2, arg3, arg4, arg5 )
#define MSG6( fmt, arg1, arg2, arg3, arg4, arg5, arg6)
is there any way of defining just one macro that can accept any number of arguments?
thanks
Well since @GMan didn’t want to put that as an answer himself, have a look at variadic macros which are part of the C99 standard.
Your question is tagged C++ though. Variadic macros are not part of the C++ standard but they are supported by most compilers anyway: GCC and MSVC++ starting from MSVC2005.