473,503 Members | 3,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use if else macro while compilation

I have cpp file with :

#if 1
#include"myfile.h"
#else
#include "libfile.h"
#endif

how it works ?

Sep 19 '07 #1
6 4881
devphylosoff wrote:
I have cpp file with :

#if 1
#include"myfile.h"
#else
#include "libfile.h"
#endif

how it works ?
The preprocessor lets through everything between '#if 1' and '#else'
and drops everything between '#else' and '#endif'. The result of
the filtering is

#include"myfile.h"

which then preprocessed, and then the code from 'myfile.h' is itself
included and preprocessed.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 19 '07 #2
On Sep 19, 9:44 pm, devphylosoff <devp...@gmail.comwrote:
I have cpp file with :

#if 1
#include"myfile.h"
#else
#include "libfile.h"
#endif

how it works ?
w.r.t. subject line: "macros" are considered in the pre-processing
stage, which comes before compilation.

The preprocessor evaluates the #if macro and expands the appropriate
clause(s).
In the above example, since 1 evaluates to true, the file "myfile.h"
will get included.

-N

Sep 19 '07 #3
rights, #if 1 is always true, so if I need switch I should use
different condition.

for example
#if sth
....

and compile with -Dsth.
it's really no way to make #if 1 equals false using -D ?
Sep 19 '07 #4
devphylosoff <de*****@gmail.comwrites:
I have cpp file with :

#if 1
#include"myfile.h"
#else
#include "libfile.h"
#endif

how it works ?
Any textbook on C or C++ should explain that. If condition given in #if
statement is true the portion between #if and #else will be compiled
otherwise the part between #else and #endif. (There is also #ifdef,
#ifndef, #elsif.)

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo--
Sep 19 '07 #5
"Michal Nazarewicz" <mi****@tlen.plwrote in message
news:87************@erwin.mina86.com...
[...]
Any textbook on C or C++ should explain that. If condition given in #if
statement is true the portion between #if and #else will be compiled
otherwise the part between #else and #endif. (There is also #ifdef,
#ifndef, #elsif.)
[...]

#elif

Sep 19 '07 #6
"Michal Nazarewicz" <mi****@tlen.plwrote:
>Any textbook on C or C++ should explain that. If condition given in #if
statement is true the portion between #if and #else will be compiled
otherwise the part between #else and #endif. (There is also #ifdef,
#ifndef, #elsif.)
"Chris Thomasson" <cr*****@comcast.netwrites:
#elif
Bah... Too much Perl. :P

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo--
Sep 19 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
25371
by: Ced | last post by:
Hi, i'm not an expert in C but i try to compile BTNG software under linux kernel 2.4.2-2. I get these errors at the very first stage. Does someone could have a rapid look on this and tell me...
27
31802
by: Yan | last post by:
A lot of times when reading open software, i come across macros that are defined as follows: #define CALL_FUNCS(x) \ do { \ func1(x); \ func2(x); \ func3(x); \ } while (0);
17
2138
by: Russell Shaw | last post by:
Hi, How do i make an if/then/else macro act as a function so that the whole thing looks like the return value? I tried this lame attempt for starters: #define A_FROM_B(b) \ ( \ if(b < 10)...
20
7714
by: Srinivas Mudireddy | last post by:
Hi, I am facing a problem with trying to conditionally compile inside a macro. I have a macro #define SET_VAL(x, y) ((x) = *(y)) But the problem is y can be NULL in which case I want to set...
28
2606
by: richardlang | last post by:
Anyone out there ever come across a preprocessor macro that compares an argument value against the predefined __DATE__ macro in order to control conditional compilation based on date. Something...
3
4214
by: ezmeralda | last post by:
Hello, I have some code which shall be compiled in .NET v1.1 and v2.0 but which has to be different for the two .NET-Versions. Therefore I need to use a construct like #if NET_20 <2.0...
3
377
by: sam_cit | last post by:
Hi All, I have the following scenario, A class is declared in the header file and has a static member function sample() in sample.h sample.cc uses the static member function sample(). the...
5
1652
by: Rahul | last post by:
Hi Everyone, I have the following files, file.h typedef struct { int data;
33
15132
by: Peng Yu | last post by:
Hi, __PRETTY_FUNCTION__ is a macro that gives function name, etc. I'm wondering if there is a macro to get the class name inside a member function. Thanks, Peng
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.