473,325 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

"#if defined" clause intersected

Hi, i'd like to have code blocks A and B if AB is defined
and B and C block if BC is defined.
is the writing below correct ?


Expand|Select|Wrap|Line Numbers
  1. void func(...)
  2. #if defined AB
  3. A
  4. #if defined BC
  5. B
  6. #endif
  7. C
  8. #endif
  9.  

thanks,
Nov 7 '10 #1
3 2145
weaknessforcats
9,208 Expert Mod 8TB
The usual practice is to use the macro to provide different code so when you run the program you can see what happened.

Either that, or you need to intercept the translation unit file that is being sent to the compiler.
Nov 7 '10 #2
Banfa
9,065 Expert Mod 8TB
Since B is always included it should not be inside any preprocessor conditional. Use the symbols to control the inclusion of A and C

Expand|Select|Wrap|Line Numbers
  1. void func(...)
  2. {
  3. #if defined AB
  4. A
  5. #endif
  6. B
  7. #if defined BC
  8. C
  9. #endif
  10.  
Nov 7 '10 #3
donbock
2,426 Expert 2GB
Hi, i'd like to have code blocks A and B if AB is defined and B and C block if BC is defined.
Please clarify your requirements. There are four possibilities: neither are defined, both are defined, only AB defined, only BC defined. My guess is that you desire the following behavior:
Block: both, neither, only AB, only BC
A: yes, no, yes, no
B: yes, no, yes, yes
C: yes, no, no, yes
Is this what you want?

You stated the problem in terms of desired behavior for each control variable. It would be clearer to state the inclusion rules for each block:
Block A is present if AB is defined.
Block B is present if either AB or BC are defined.
Block C is present if BC is defined.
(If that is indeed the behavior you want.)

Thus:
Expand|Select|Wrap|Line Numbers
  1. #if defined(AB)
  2. A
  3. #endif
  4. #if defined(AB) || defined(BC)
  5. B
  6. #endif
  7. #if defined(BC)
  8. C
  9. #endif
I elected to use #if syntax instead of #ifdef syntax in order to support the logical expression for block B. I then used the same syntax for blocks A and C for consistency. In my opinion the inclusion logic is harder to understand if you nest the preprocessor statements.

Suppose you only want to include block C if BC is defined, but AB isn't. Then you would do this:
Expand|Select|Wrap|Line Numbers
  1. #if !defined(AB) && defined(BC)
  2. C
  3. #endif
Nov 8 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: george young | last post by:
I had developed the habit of using the neat python form: if someinstance: someinstance.memb() because it seems cleaner than "if someinstance is not None". {please no flames about "is not None"...
5
by: kmunderwood | last post by:
I am trying to combine "if match=" and "when test" I am a newbie, and have made both work separately, but I can not seem to combine them. This is my xml("index.xml")page(I can not change this,...
10
by: qazmlp | last post by:
There are some blocks of C/C++ code put under #if 0 #end if Is there anyway to make the code inside these blocks to get executed (may be by using some command line options)?
12
by: junky_fellow | last post by:
Which is better using a switch statement or the if-then equivalent of switch ?
0
by: David Gresty | last post by:
I am developing a web applications that uses lots of data forms to display, input and update. During development, I have tested the code, adapters and datasets and they work great. Nearing the...
10
by: Eric G. Harrison | last post by:
We have a project with many other projects referenced (all of which are referenced at the project level and are included in the solution). Frequenly, if we make a change in project A (such as adding...
2
by: Yarik | last post by:
Hello, I am not sure the subject of my post adequately describes the problem I am trying to solve, so I think a specific example would be helpful. Let's say there are XML descriptions of...
4
by: Sarcastic Zombie | last post by:
Good morning, If I have a class class A: __init__(id) self.id = id is there any way to overload the 'if' unary usage to detect if a variable has a value?
7
by: itsraghz | last post by:
Hello All, I remember in MySQL we do have "IF EXISTS", 'IF NOT EXISTS" clause/keyword in the DDL statements (CREATE,DROP etc.,) to avoid unnecessary bombing. Do we have such facility in...
10
prn
by: prn | last post by:
I have some inherited code that I don't understand properly. It involves sending email from Access using OLE and Outlook. I've stripped it down to the relevant bits here. Specifically, the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.