A preprocessor cannot use variables from program C in expressions - it can only act on preprocessor macros. Therefore, when you try to use c in the preprocessor, you will not get what you expect.
However, you also do not get an error, because when the preprocessor tries to evaluate an identifier that is not defined as a macro, it treats the identifier as having a value of 0.
So, when you click this snippet:
#if c==1
c used by the preprocessor has nothing to do with the variable c from program C. The preprocessor looks to see if there is a macro defined for c . Since no, it evaluates the following expression:
#if 0==1
which of course is not true.
Since you are not using the variable c in your program, you can do the following to get the behavior according to what you are trying:
#define C 1 #if C==1 #define check(a) (a==1)?a:5 #define TABLE_SIZE 100 #endif
(Note that I also capitalized the macro according to the convention for macro names.)
Michael burr
source share