LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 03-20-2011, 01:57 AM   #1
rainman1985_2010
Member
 
Registered: Oct 2010
Posts: 47

Rep: Reputation: 0
How to test whether a macro is defined


Hi guys:
I've been reviewing some source code recently which contains many conditional compilation statements, and I found it hard to understand the code not knowing whether some macro is defined or not.

Is there any way to test whether a macro is defined?

Last edited by rainman1985_2010; 03-20-2011 at 01:58 AM.
 
Old 03-20-2011, 02:22 AM   #2
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
#ifdef: http://gcc.gnu.org/onlinedocs/cpp/Ifdef.html
 
Old 03-20-2011, 06:37 AM   #3
lumak
Member
 
Registered: Aug 2008
Location: Phoenix
Distribution: Arch
Posts: 799
Blog Entries: 32

Rep: Reputation: 111Reputation: 111
Also note, that if these are the very things that are confusing you, your IDE should be able to track were they are '#define macro_name'... if not, just grep for that with options for ignore case and white space.

If you need to track them at run time, you would have to define a variable and or output to a file when something is defined... or where you choose by using #ifdef...

If you had a section of code that wrote some information to a file for testing these it could be something like

// open file buffer
#ifdef macro1
// write text 'macro1' to file buffer
#endif
#ifdef macro2
// write text 'macro2' to file buffer
#endif
// close file buffer

Of course you could also use this in your help output regarding compile flags.
 
  


Reply



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
C++: Macro not defined in quotes!? CoderMan Programming 2 12-12-2009 11:39 PM
Way to convert Macro Defined functions from linux Kernel in Visual C++ Kunsheng Programming 5 06-29-2009 09:25 AM
where defined(__i386) is being defined?? syseeker Programming 1 06-27-2006 06:24 AM
#defining a macro inside a macro? saravkrish Programming 1 05-24-2005 09:48 PM

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

All times are GMT -5. The time now is 07:53 PM.

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