I’ve write something like below:
#define ABC20
//#define ABC10
//#define ABC00
#ifdef ABC20
#define SYSTEMNAME "ABC2"
#elif ABC10
#define SYSTEMNAME "ABC1"
#elif ABC00
#define SYSTEMNAME "ABC0"
#else
#define SYSTEMNAME "UNKNOWN"
#endif
And it can work.
But if I change to below:
//#define ABC20
#define ABC10
//#define ABC00
#ifdef ABC20
#define SYSTEMNAME "ABC2"
#elif ABC10
#define SYSTEMNAME "ABC1"
#elif ABC00
#define SYSTEMNAME "ABC0"
#else
#define SYSTEMNAME "UNKNOWN"
#endif
When I compiled, it got error saying ABC10 is not declared. Do you guys know why?
Use defined test:
otherwise there is no condition for elif to check because after pre-processing you are left with:
but putting in the
definedreplaces the test with the result so you get:Alternatively, you can define on flags with a
truevalue, and rest of the flags with a false value without changing the tests: