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.

Basic C programming question

Status
Not open for further replies.

arm_learner

Member level 2
Member level 2
Joined
Jan 6, 2004
Messages
42
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
322
Basic C Programming

#define Z 1
#if Z
A
#else
B
#endif
********************
I want to know Z will select A or B?
Thz!
 

Re: Basic C Programming

A will be chosen.

0 will be mapped to FALSE.
Anything else will be mapped to TRUE.
 

Re: Basic C Programming

it will certainly select A
 

Basic C Programming

certainnly A is chosen!
 

Re: Basic C Programming

WE CERTAINLY GET A BECAUSE WE HAVE DEFINED Z=1 .
 

Basic C Programming

It will definitely be A.

You defined Z=1

if Z=1 -> A
else if Z= 0 -> B

s2c97
 

Re: Basic C Programming

As everybody else stated, It will select A. The reason being simple that the preprocessor will simply replace 'Z' with '1' wherever it encounters Z. So the preprocessor output will be like

#if 1
A
#else
B
#endif

which obviously results in A.

DigitalScholar
 

Basic C Programming

which obviously results in A
 

Basic C Programming

This is a very simple question.
A will be chosed.
 

Re: Basic C Programming

This will help some one to develope code during degugging. And than deleting
the code of the 0 part.
 

Re: Basic C Programming

arm_learner said:
#define Z 1
#if Z
A
#else
B
#endif
********************
I want to know Z will select A or B?
Thz!

There's another way to do this which I personally prefer.

#define DEBUG // use #undef DEBUG if not in debug mode
#if defined (DEBUG)
A
#elseif
B
#endif

or

#undef DEBUG
#if !defined (DEBUG)
B
#elseif
A
#endif
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top