How to compare C # define variable value

I made the following #defines

#define GOLD 1;
#define SILVER 2;

later in my program I set some variables

int source, target;

Then they are set to:

source = GOLD;
target = SILVER;

Now I want to compare in the if statement:

if(source == GOLD) {...}

But the compiler complains about Waiting for ')' before ';' marker. If I changed the line to

if(source == 1) {...}

No problem with compiler or behavior. How can I refer to #define in an if statement so that I can verify the compiler?

+3
source share
1 answer

Because you have wandering ;after #define GOLD 1and #define SILVER 2. Remove them, your problem will disappear.

+11
source

Source: https://habr.com/ru/post/1781586/


All Articles