# Macro's and variable length args

This topic is 3701 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I have a message log and its function to log a message is this...
void log(LogMessageType messageType,
string message,
const string fileName,
const int lineNumber,
const string functionName);


so I wrote a handy macro that i could call to log the message...
#define logMessage(type,message)(MessageLog::getInstance()->log(type, message, __FILE__, __LINE__, __FUNCTION__))


So today I added support so the log could take extra parameters such as in in so the message could be like this "Loaded %i files" and it works fine, but im wondering how i can pass the variable args via the macro? Thanks for any help. heres the new calls if they help with the problem...
void log(LogMessageType messageType,
string message,
const string fileName,
const int lineNumber,
const string functionName, ...);


#define logMessage(type,message,...)(MessageLog::getInstance()->log(type, message, __FILE__, __LINE__, __FUNCTION__))



##### Share on other sites
Vararg macros are included in C99, but I don't know how supported that is. I think GCC has had an extension for this for some time.

Best to stick with more C++ style methods such as boost::format, or similar operator chaining methods.

##### Share on other sites
I agree with rip-off, but if you really need to use variadic functions, and you're using Visual Studio 2005 or later, you can use the __VA_ARGS__ predefined macro which expands to whatever you have in the ... part of your macro.

But variadic functions are evil anyway...

Cheers guys