By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,131 Members | 1,977 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,131 IT Pros & Developers. It's quick & easy.

Commenting out debug code

P: n/a
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


Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
Jul 22 '05 #2

P: n/a
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
Jul 22 '05 #3

P: n/a
ak
On Thu, 27 May 2004 10:35:22 +0000 (UTC), "Michael" <sl***********@hotmail.com>
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
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.