Link to home
Start Free TrialLog in
Avatar of perlperl
perlperl

asked on

if def in c++

I have the noticed the following in code path

#if SOME == 1
   // Do someting
#else
   // Do something
#endif

Open in new window


How can we set the variable SOME, is this something set using environment variable from the bash shell before executing the executable?
ASKER CERTIFIED SOLUTION
Avatar of egarciat
egarciat

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of perlperl
perlperl

ASKER

ohhhh I see its at the compile time.
Thanks a lot!!
Avatar of chaau
Just wanted to add (please do not award me any points, as you have already got your answer). The very same "variable" can be defined as a #define macro:
#define SOME 1
#if SOME == 1
   // Do someting
#else
   // Do something
#endif

Open in new window

Adding to the above comment,
In comanddline, we can only define a macro which helps for #ifdef/#ifndef ..etc. But for #if we have to specify a value to make it scence.
Ex:
#define SOME 1
......
......
#if SOME == 1
   // Do someting===============>This wil execute.
#else
   // Do something
#endif
#############################################################
#if is simillar to if-else stateent but difference is, if-else is taking the value from variable and that variable needs to be defined. But in #if, it takes the value defined by #define
Thanks a lot everyone for comments.