LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   #ifdef APP_DEBUG (https://www.linuxquestions.org/questions/linux-newbie-8/ifdef-app_debug-645460/)

jodie 05-28-2008 08:59 PM

#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

grizly 05-28-2008 10:16 PM

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

Quote:

#define APP_DEBUG TRUE //Debugging on

jodie 05-29-2008 12:25 PM

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

grizly 05-29-2008 07:34 PM

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

Did you read the links?

Google

i92guboj 05-29-2008 07:41 PM

Quote:

Originally Posted by jodie (Post 3168284)
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.

grizly 05-29-2008 09:46 PM

Quote:

Originally Posted by i92guboj (Post 3168681)
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++..


All times are GMT -5. The time now is 04:54 AM.