X
Xiaoxiao
Hello:
I need to get something like only #define something when a condition
is true, but I can't get it.
For example, if a variable a is set, then I will #define something;
and later on I will only output something when something is #defined.
int a=1; // 1 is just an example
if (a)
#define DBG
.......
#ifdef DBG
fprintf(stderr, "DBG is defined!\n");
#endif
The reason I need to do this is because I had the later part of code
already and don't want to change it because there are lots of them in
the code,
(#ifdef DBG
fprintf(stderr, "DBG is defined!\n");
#endif),
but now I only want to let this part of code be run when a variable
(say a here is set). Or actually, I need to do something like:
#if defined(DBG) || a
then do something
#endif
and the problem is that my a is a variable but not a constant, say if
it is from class A, I can get it like A::a.
I tried
#if defined(DBG) || A::a
then do something
#endif
but I got errors. So I am thinking to only #define DBG when A::a is
set, but it seems the below code will not work as I like:
if (A::a)
{
#define DBG
}
It always do the #define DBG even if the condition of if(A::a) is not
met.
Any help will be appreciated, and sorry for anything unclear in this
post in advance.
Xiaoxiao
I need to get something like only #define something when a condition
is true, but I can't get it.
For example, if a variable a is set, then I will #define something;
and later on I will only output something when something is #defined.
int a=1; // 1 is just an example
if (a)
#define DBG
.......
#ifdef DBG
fprintf(stderr, "DBG is defined!\n");
#endif
The reason I need to do this is because I had the later part of code
already and don't want to change it because there are lots of them in
the code,
(#ifdef DBG
fprintf(stderr, "DBG is defined!\n");
#endif),
but now I only want to let this part of code be run when a variable
(say a here is set). Or actually, I need to do something like:
#if defined(DBG) || a
then do something
#endif
and the problem is that my a is a variable but not a constant, say if
it is from class A, I can get it like A::a.
I tried
#if defined(DBG) || A::a
then do something
#endif
but I got errors. So I am thinking to only #define DBG when A::a is
set, but it seems the below code will not work as I like:
if (A::a)
{
#define DBG
}
It always do the #define DBG even if the condition of if(A::a) is not
met.
Any help will be appreciated, and sorry for anything unclear in this
post in advance.
Xiaoxiao