How to compare value of variable against #define
I have made the following #defines
#define 开发者_运维百科GOLD 1;
#define SILVER 2;
later in my program I set up some variables
int source, target;
They are then set to the values:
source = GOLD;
target = SILVER;
I now want to compare in an if statement:
if(source == GOLD) {...}
But the compiler complains Expected ')' before ';' token. If I change the line to
if(source == 1) {...}
There is no problem with the compiler or the behavior. How do I reference the #define in the if statement to make myself clear to the compiler?
Because you have an errant ;
after the #define GOLD 1
and #define SILVER 2
. Remove them, your problem will go away.
精彩评论