Question

I defined a macro to DbgPrint to prints message when the _DEBUG defined

#define MYDBGPRINT(X) #ifdef _DEBUG \
    DbgPrint(X) \
#endif

but the output is differ from the DbgPrint for example

ULONG id=0;
MYDBGPRINT("the value of the id : %u ",id)  //outputs garbage
DbgPrint("the value of the id : %u ",id)  //outputs the correct value of id
Was it helpful?

Solution

You are trying to use the pre-processor to create pre-processor definitions. I've never tried that myself, but it seems like a bad idea that probably won't work. Instead try something like:

#ifdef _DEBUG
#define MYDBGPRINT(X) DbgPrint(X)
#else
#define MYDBGPRINT(X)
#endif

or in the case of having a variable number of arguments to your macro:

#ifdef DEBUG
#define MYDBGPRINT(...) DbgPrint(__VA_ARGS__)
#else
#define MYDBGPRINT(...)
#endif
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top