Commenting out debug code

M

Michael

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
 
J

Jacques Labuschagne

Michael said:
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.
 
G

Gernot Frisch

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
 
A

ak

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top