I am trying to check using #if, that a macro and enum are equal or not. the check fails even if both has same value. why?
Created a macro using #define NUMBER 2. Created enum including one entry with value 2. compared both using #if . compared macro with 2 is getting passed. but comparing macro with enum fails.
#include <stdio.h>
#define NUMBER 2
enum numbers
{
zero = 0,
one,
two,
three
};
int main ()
{
printf("NUMBER: %x and two: %x\n", NUMBER, two);
#if NUMBER == two
printf("#1-------PASS\n");
#else
printf("#1--------FAIL\n");
#endif
#if NUMBER == 2
printf("#2-------PASS\n");
#else
printf("#2--------FAIL\n");
#endif
if (NUMBER == two)
printf("#3-------PASS\n");
else
printf("#3--------FAIL\n");
}
I expected PASS for all three cases. Actual result:
NUMBER: 2 and two: 2
#1--------FAIL
#2-------PASS
#3-------PASS