After years of mostly using gcc, I suddenly have a need to use Visual C on Windows. The latest thing I need to translate is this:
#ifdef DBG_ENABLE
#define DBG_PRINT(x...) printf(x)
#else
#define DBG_PRINT(x...)
#endif
Which gives me this error:
error C2010: '.': unexpected in macro parameter list
Can someone please share the Windows way of doing this?
I tried googling and searching the Microsoft docs, but couldn't figure out a way to phrase the question that brought relevant results.
CodePudding user response:
#define DBG_PRINT(x...) printf(x)
is not the correct syntax for using variadic macros in VC .
Per Microsoft documentation on Variadic macros, try this instead:
#ifdef DBG_ENABLE
#define DBG_PRINT(...) printf(__VA_ARGS__)
#else
#define DBG_PRINT(...)
#endif
Or:
#ifdef DBG_ENABLE
#define DBG_PRINT(s, ...) printf(s, __VA_ARGS__)
#else
#define DBG_PRINT(s, ...)
#endif