可变参数宏定义,window和linux下可能会有不同,但大同小异,都是以以下几种形式:
#define debug(format, …) fprintf(stderr, fmt, _VA_ARGS_)
#define debug(format, args…) fprintf (stderr, format, args)
#define debug(format, …) fprintf (stderr, format, ## _VA_ARGS_)
下面给出一个小例子:
void DebugString(LPCTSTR pszFmtMsg, ...)
{
char strBuffer[1024]={0};
#ifdef _DEBUG
va_list pArgs;
va_start(pArgs, pszFmtMsg);
//CString strBuff;
//strBuff.FormatV(pszFmtMsg, pArgs);
vsprintf(strBuffer, pszFmtMsg, pArgs);
OutputDebugString(strBuffer);
printf(strBuffer);
va_end(pArgs);
#endif
}
#define DebugPrint(format, ...) DebugString("[%s %d] "format, __FUNCTION__, __LINE__, ##__VA_ARGS__)
int _tmain(int argc, _TCHAR* argv[])
{
char abc[64] = "I am a test";
int a = 1;
DebugPrint("%s %d\n", abc, a);
system("pause");
return 0;
}