Debug functions

Started by
3 comments, last by Psepha 24 years, 6 months ago
That's pretty much the coding standard where I work and it works pretty well.

Not much more I can say

Advertisement
I recommend using #if over #ifdef so you should

#define _DEBUG_ 1 // 0 to turn it off

and use #if because if you mistype _DEBUG_ the compiler will complain.

I agree with Void about using #if instead of #ifdef

I often setup a scheme where I have multiple levels of debug, and I like being able to do

#if (DEBUG_LEVEL > 0)
...
#endif

for code that should always report debug information when debugging,

or

#if (DEBUG_LEVEL > 5)
..
#endif

for code that should only display debug information if I have set: #define DEBUG_LEVEL 6. This lets me cascade the error reporting. Sort of like you always want to report frame per second readouts, but not always whether your flip succeeded or not. Also think about using macros as reporting tools that are defined as doing nothing when not in debug mode, but do something else when debugging. This might be cleaner:


if (condition == FALSE)
{
DEBUG_REPORT("message");
return FALSE;
}

and the macro changes DEBUG_REPORT to doing nothing if DEBUG_LEVEL == 0.

I don't know I don't use that myself, but I have seen it used elsewhere.

Just a general coding practice question is all......
For example I have a Network.dll err, well, dll really. If I want to create a debug version of this class (for that is what it is before compilation) is it an OK thing to code eg
Network::Network( char Param1,
#ifdef _DEBUG_
Debugger* DebugModuleClass,
#endif
char Param2 )
{

}
and then stick the #ifdef statement round bits of code that call the debugger? I know the whole kit and kaboodle will require a total recompilation to insert/remove the debug code but it seems to fit the bill. Any glaringly obvious mistakes/"You can't seriously do that!" comments?

Ta
Psepah

Thanks for the feedback people. Looks like I am in the right area anyway.

Psepha

This topic is closed to new replies.

Advertisement