LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-25-2005, 10:25 PM   #1
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Rep: Reputation: 30
DEBUG statement question


when looking at some c code. I found the following statement alot of the time and want to know what it does,

Code:
DEBUG('t', "a message");
is this a function that puts your program in debug mode, and does this help you out in big programing projects?


thanks,
djgerbavor3
 
Old 01-25-2005, 10:34 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
I'm guessing that is a macro defined somewhere in the project. As far as I know there is no DEBUG function in any of the stdlib's.

What I usually do is have a macro function called PRINTDB that is just a wrapper for printf basically. However, I set it up so it only gets defined so you see output if the symbol DEBUG is defined. So you can determine at compile time whether or not the debug messages will get printed.
 
Old 01-26-2005, 09:33 AM   #3
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Wow, i've been stupid. I'm not sure I should publically admit this, but I've been stupid enough to do:
Code:
#ifdef DEBUG
fprintf(stderr,"DEBUG: MESSAGE");
#endif
...
I guess the following would make more sense:
Code:
#define DBGMSG(x) fprintf(stderr,"DEBUG: %s\n",(x))
and then use that. Or perhaps I can find some way to emulate printf with variable length arguments... as in
Code:
DBGMSG("ival: %d xval: %d\n",1,2);
giving me, on stderr:
Code:
DEBUG: ival: 1 xval: 2
 
Old 01-26-2005, 09:37 AM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
I use the C99 standard... but this is how I do it:

Code:
#define DEBUGMSG(format, ...) fprintf (stderr, format, __VA_ARGS__)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[Question]kernel debug/ trace shogun1234 Linux - Newbie 0 09-21-2004 09:40 PM
[debug]what does the following debug information mean icoming Programming 21 06-08-2004 02:13 AM
for statement c code question dragoon linux Programming 3 12-31-2003 11:17 AM
bash if statement question xscousr Programming 3 09-02-2003 11:58 AM
question about C 'for' statement ... purpleburple Programming 8 08-25-2002 07:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration