Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 977
StoneBreaker Avatar asked Dec 16 '22 19:12

StoneBreaker


1 Answers

Because you have an errant ; after the #define GOLD 1 and #define SILVER 2. Remove them, your problem will go away.

like image 60
jer Avatar answered Dec 28 '22 04:12

jer