Let's say the following code is required to be compatible with three versions
This will not complete the task.
No matter
typedef enum{first,second,third,}; #define NUM third#if (num = = first) #define VAR 1#elif (num = = SECOND) # Define var 2#elif (num = = third) #define var 3#endifint main (void) {#if (num = = first) printf ("VAL =%d\n" , Var), #elif (num = = SECOND) printf ("val =%d\n", var), #elif (num = = third) printf ("val =%d\n", var); #endif}
#define NUM First or
#define NUM Second or
#define NUM Third
The results are all the same
But then we can do the job.
#define FIRST 1#define SECOND 2#define third 3#define num third#if (num = = first) #define VAR 1#elif (num = SECOND) #define var 2#elif (num = = third) #define var 3#endifint main (void) {#if (num = = First) printf ("val =%d\n", var), #elif (num = = SECOND) printf ("val =%d\n", var), #elif (num = = third) printf ("val =%d\n", var); #endif}
#define NUM First or
#define NUM Second or
#define NUM Third
Can get the results you want.
Why?????
#if #elif Considerations when using #define TypeDef