LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-28-2008, 08:59 PM   #1
jodie
LQ Newbie
 
Registered: Sep 2007
Posts: 10

Rep: Reputation: 0
#ifdef APP_DEBUG


Hi All,

I have seen a lot of C++ codes have the following:
#ifdef APP_DEBUG

<pirntf statement>

#endif

Can you please explain when/how to make these printf statement inside the #ifdef executed. Where I can define APP_DEBUG to be true so the printf statement will be executed. This is C++ on Linux box

Thanks,

JP
 
Old 05-28-2008, 10:16 PM   #2
grizly
Member
 
Registered: Nov 2006
Location: Melbourne Australia
Distribution: Centos, RHEL, Debian, Ubuntu, Mint
Posts: 128

Rep: Reputation: 16
http://www.fredosaurus.com/notes-cpp...sor/ifdef.html
http://www.cprogramming.com/tutorial/cpreprocessor.html

Quote:
#define APP_DEBUG TRUE //Debugging on
 
Old 05-29-2008, 12:25 PM   #3
jodie
LQ Newbie
 
Registered: Sep 2007
Posts: 10

Original Poster
Rep: Reputation: 0
Hi,
Thanks for the answer but Is there anyway that I can set the variable at command prompt for APP_DEBUG and export that variable to make APP_DEBUG become TRUE so the printf statement will be executed.

If I add #define APP_DEBUG TRUE then I need to recompile the code again and I don't want to do that.
Thanks
JP
 
Old 05-29-2008, 07:34 PM   #4
grizly
Member
 
Registered: Nov 2006
Location: Melbourne Australia
Distribution: Centos, RHEL, Debian, Ubuntu, Mint
Posts: 128

Rep: Reputation: 16
Well, that pragma is surely designed for the programmer.. not the user. Programmers get used to recompiling.

Did you read the links?

Google
 
Old 05-29-2008, 07:41 PM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by jodie View Post
Hi,
Thanks for the answer but Is there anyway that I can set the variable at command prompt for APP_DEBUG and export that variable to make APP_DEBUG become TRUE so the printf statement will be executed.

If I add #define APP_DEBUG TRUE then I need to recompile the code again and I don't want to do that.
Thanks
JP
This stuff, as someone said, is intended for programmers only. So, you have to define the macro if you want to get the debug info (and recompile afterwards).

You can also re-make the stuff by defining this at the command line like "make -DDEBUG" (or whatever the macro is called on your program).

If you intend to implement debug stuff that can be accesible by the user, you should be looking at adding one parameter to your program. Then read it in main, if the given param is enabled, then printf whatever.
 
Old 05-29-2008, 09:46 PM   #6
grizly
Member
 
Registered: Nov 2006
Location: Melbourne Australia
Distribution: Centos, RHEL, Debian, Ubuntu, Mint
Posts: 128

Rep: Reputation: 16
Quote:
Originally Posted by i92guboj View Post
You can also re-make the stuff by defining this at the command line like "make -DDEBUG" (or whatever the macro is called on your program).

If you intend to implement debug stuff that can be accesible by the user, you should be looking at adding one parameter to your program. Then read it in main, if the given param is enabled, then printf whatever.
I didn't know about the "make -D" thats cool..

Also, that google link is how to use command line arguments with C++..
 
  


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
ifdef not working in GNU make version 3.80 jennifer29 Programming 5 12-19-2011 05:40 PM
Problem running ifdef in GNU make 3.80 jennifer29 Linux - Newbie 1 03-03-2006 05:56 AM
ifdef for suse?? nkshirsagar SUSE / openSUSE 2 01-11-2005 12:12 AM
Compiling programmes: How to use #ifdef? asciimonster Linux - General 1 12-13-2004 02:35 PM
help with #ifdef #undef etc tuxfood Programming 3 06-29-2004 09:12 AM


All times are GMT -5. The time now is 01: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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration