Excluding User Code from Compiling

Top  Previous  Next

If you have code that is only called by debugging routines or unit testing routines, you can enclose it in #ifdef blocks conditioned on debug compilation.

 

If JrDebugLog is compiled into your code the following symbols are defined:

       #define JrDebuggingFlag true

       #define JrDebugging

 

If JrDebugLog is not compiled into your code, the following symbols are defined:

       #define JrDebuggingFlag false

 


So if you have some test unit code for example you might write it as follows:

 

       #ifdef JrDebugging

               // code for the unit tests

               void MyUnitTest()

                       {

                       dbprintf("my unit test!");

                       }

               // register the unit tests - this is all you have to do to tell the system about your test functions

               JrDebugRegisterTestFunction("Simple Unit Test",MyUnitTest,"simple");

       #endif

 

In this way, the testing code will not be compiled in if the program is built without JrDebugLogging code.