Hello, I'm using KEIL V5.10 with STM32F103. My project has some enum type variables, such as typedef enum { a0 = 0, a1, a2, an } aType;
In source file, I used conditional compile statements:
#if (an > 0) xxxx #endif
But the body inside was not compiled whatever an is higher than zero, I don't know why.
An array can be correctly complied if I used an as array's length, such as
static uint16_t u16Buf[an];
There is no warning or error after compilation.
Anyone knows why the conditional compilation does not work?
Thanks!
The "an" can only be larger than zero if you have any other enum value before.
So it feels more like you should write the code:
#if HAVE_FEATURE_XX enum { a0,a1,...,an } #endif // HAVE_FEATURE_XX . . . #if HAVE_FEATURE_XX for (unsigned i = 0; i < an; ++i) { do_magic(i); } #endif // HAVE_FEATURE_XX
Because as I read it, "an" is intended to be the number of enumerated values, in which case the whole enumerator becomes irrelevant if you haven't any enumerated values to care about.
@Per Westermark
Yes, you are right, I use "an" as the number of enum parameters, and I did like you did in my project and there was no problem.
My problem is whatever "an" is, the conditional compilation always thinks an=0, so statements does not compiled, because gcc does not support enum type in conditional compilation directives.