473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Commenting out debug code

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
3 2196
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: qazmlp | last post by:
I hope comp.lang.c will not find the following question as a complete off-topic. I would like to remove ie.comment out the 'cout' statements during compilation(actually preprocessing) time. ...
46
by: Profetas | last post by:
Hi, I know that this is off topic. but I didn't know where to post. Do you comment your source code while coding or after coding. for example: you write a procedure and after it is...
4
by: Ron McNulty | last post by:
Often when testing an app, I want to temporarily comment out sections of the App.config file. Is there any way to do this? Regards Ron
3
by: Naveen Mukkelli | last post by:
Hi All, I'm trying to create XML commenting for my code using XML commenting feature for the first time. I'm using VS.NET 2003 and C#. I'v tried the following way. Step 1: set the file name...
18
by: Marian F. | last post by:
The 12 years old genius function to count english words in a sentence: ' This is my function to count english words in your string ' s is the string with your words to be counted ' Returns an...
8
by: lallous | last post by:
Hello I've been programming for a number of years, however my commenting style is always different. Sometimes I use something like: /************************ * method .... * comments......
2
by: RYoung | last post by:
Can someone point me to a reference concerning source code commenting with VB 2005, ala C# commenting? I googled and found alot of links to add-ins and commercial products, but I can't find any...
1
by: Wijaya Edward | last post by:
Hi all, I have the following code: import sys import re ham_count = 0 spam_count = 0
100
by: Angel Tsankov | last post by:
Can someone recommend a good source of C/C++ coding style. Specifically, I am interested in commenting style and in particular how to indent comments and the commented code, rather than when to...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.