Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Commenting out debug code

Reply
Thread Tools

Commenting out debug code

 
 
Michael
Guest
Posts: n/a
 
      05-27-2004
OK Guys, lets say that I've got some code that I want from time when I'm
debuging but want to be able to turn off quickly.
At the moment I'm doing:


#define DEBUG_TEXTURE
#define DEBUG_BSP
#define DEBUG_COLLISION



//Do Stuff:

#ifdef DEBUG_TEXTURE
//Debuging code;
//OutPuting to file/console
#endif

//More Stuff

#ifdef DEBUG_BSP
//Debuging code;
#endif

however my debug lines are normally only 1 line, so I end up with really
messy code.

What I'd like to do is:


#define DEB_BSP //

//then in code
DEB_BSP cout <<" Debug Info";


but the double forward slash wouldn't work with the #define.

What do others do to get around this? Is my original method the only way?

I could do

#define DEB_BSP 1 //make 0 to disable


if( DEB_BSP) cout << "Debug output";
but this isn't really great because I'll incur quite a performance hit at
runtime with lots of if statements!

Thanks in advance



Mike








 
Reply With Quote
 
 
 
 
Jacques Labuschagne
Guest
Posts: n/a
 
      05-27-2004
Michael wrote:
> OK Guys, lets say that I've got some code that I want from time when I'm
> debuging but want to be able to turn off quickly.
> At the moment I'm doing:
>
>
> #define DEBUG_TEXTURE
> #define DEBUG_BSP
> #define DEBUG_COLLISION
>
>
>
> //Do Stuff:
>
> #ifdef DEBUG_TEXTURE
> //Debuging code;
> //OutPuting to file/console
> #endif
>
> //More Stuff
>
> #ifdef DEBUG_BSP
> //Debuging code;
> #endif
>
> however my debug lines are normally only 1 line, so I end up with really
> messy code.
>
> What I'd like to do is:
>
>
> #define DEB_BSP //
>
> //then in code
> DEB_BSP cout <<" Debug Info";
>
>
> but the double forward slash wouldn't work with the #define.
>
> What do others do to get around this? Is my original method the only way?
>
> I could do
>
> #define DEB_BSP 1 //make 0 to disable
>
>
> if( DEB_BSP) cout << "Debug output";
> but this isn't really great because I'll incur quite a performance hit at
> runtime with lots of if statements!


No you don't, because most compilers are smart enough to optimise out an
if(1) or if(0).

My standard debug macro is

#ifdef DEBUG
#define DOUT std::cerr
#else
#define DOUT if (false) std::cerr
#endif


Jacques.
 
Reply With Quote
 
 
 
 
Gernot Frisch
Guest
Posts: n/a
 
      05-27-2004
if( DEB_BSP) cout << "Debug output";
> but this isn't really great because I'll incur quite a performance

hit at
> runtime with lots of if statements!



I do this:
#ifdef _DEBUG
#define _dcout(a) cout << a
#else
#define _dcout(a)
#endif

_dcout("Hello" << 5 << "World");

--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com


 
Reply With Quote
 
ak
Guest
Posts: n/a
 
      05-27-2004
On Thu, 27 May 2004 10:35:22 +0000 (UTC), "Michael" <(E-Mail Removed)>
wrote:

>>if( DEB_BSP) cout << "Debug output";
>>but this isn't really great because I'll incur quite a performance hit at
>>runtime with lots of if statements


well I dont know about you but when I run in debug it is because
i want verify something or find a bug so getting a perfomance hit
isn't normally a real problem.

nowadays I always have debugging info in but can turn it off with
a switch or have varios levels of tracing info. Yes, the release
code is then slightly slower than what it would have been but i
find the benefit of always having the possibility to turn on
logging info by a customer when a problem arises to be worth it.

also there is always a risk with having a release and debug version
of a program - they have different code and could behave differently.

a.k.a. "but it works in debug mode"

/ak
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: commenting out blocks of code Peter Hansen Python 8 02-20-2006 12:42 AM
Re: commenting out blocks of code Jean-Paul Calderone Python 0 02-18-2006 02:09 AM
Re: commenting out blocks of code Paul McNett Python 1 02-18-2006 02:08 AM
java commenting out of code patrick Java 4 01-11-2006 03:05 PM
Commenting out VB code =?Utf-8?B?U2FuZHk=?= ASP .Net 5 02-03-2005 05:51 PM



Advertisments