C macros using enum
C macros using enum I am trying to use #if macros by defining the type of operation to invoke the right code, So i made a very simple example similar to what I am trying to do: #include <stdio.h> enum{ADD,SUB,MUL}; #define operation ADD int main() { int a = 4; int b = 2; int c; #if (operation == ADD) c = a+b; #endif #if (operation == SUB) c = a-b; #endif #if (operation == MUL) c = a*b; #endif printf("result = %i",c); return 0; } But unfortunately that does not work I get the following result = 8 ... if I replace The operation with numbers it works fine .... But i want it to work as it is described above. result = 8 Any help "unfortunately that does not work" is not a very good description. Do you get a compile error? a run-time crash? output different from what you expect? "Not working" covers a lot of cases without describing any. – abelenky ...
