Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to use this C conditional compilation statements

Status
Not open for further replies.

neoaspilet11

Full Member level 5
Joined
Sep 29, 2005
Messages
277
Helped
29
Reputation
56
Reaction score
8
Trophy points
1,298
Location
Cebu, Philippines
Activity points
4,048
Hello Friends,

This might sound simple:

How to use the following conditional statements

1.) #ifdef

2.) #ifundef


IF I have this
#define DEBUG_STRING 1

is

#if(DEBUG_STRING)
//... blah
#endif


equal to

#ifdef(DEBUG_STRING)
//..blah
#endif
 

They are not the same. You can use '#if' with any expression, and you use '#ifdef' with macros.

#if expression
If the value of expression is true, then the code that immediately follows the command will be compiled.

#ifdef macro
If the macro has been defined by a #define statement, then the code immediately following the command will be compiled.

The #ifdef and #ifndef directives are short forms of '#if defined(defined-value)' and '#if !defined(defined-value)' respectively. defined(identifier) is valid in any expression evaluated by the preprocessor, and returns true (in this context, equivalent to 1) if a preprocessor variable by the name identifier was defined with #define and false (in this context, equivalent to 0) otherwise. In fact, the parentheses are optional, and it is also valid to write defined identifier without them.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top