Debug macro

During testing we need to output messages to the screen. When releasing we rather want to hide these messages. This macro do the job:

#ifdef _DEBUG
#define myCout(str) do { std::cout << str; } while (false)
#else
#define myCout(str) do { ; } while (false)
#endif

Depends on the chosen configuration the one or the other part of the macro is activated:

Release
Debug

Now let use it in the code:

	Gerber* Gerber_New()
	{
		Gerber* GerberPtr = new Gerber();
		myCout("GerberLib.cpp: Gerber_New(): " << GerberPtr << endl);
		return GerberPtr;
	}

The _DEBUG variable is defined by the Visual Studio, and must not be introduced in the custom code. As far I remember it depends on three assembly/link switches: /MD[d] /MT[d] /LD[d].

Leave a Reply

Your email address will not be published.