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!
I defined four parameter groups of Modbus: coils, discrete inputs, holding registers, input registers. There is master and slave in system, they have different parameters, so there may be some groups have no parameter in slave, but they do have parameters in master.In order for consistence, I defined four groups enum type, the "an" is the count of parameters, then I originally want to use it for conditional compilation, but obviously KEIL (gcc) does not support it.
Preprocessor stuff occurs BEFORE the compiler processes the source, it's not a KEIL or GCC thing.
Use a regular 'if' construct and the let the optimizer deal with the 'if (1 == 2)' paths that are never taken.
because gcc does not support enum type in conditional compilation directives.
but obviously KEIL (gcc) does not support it.
I said before:
That won't work with any c compiler.
If you find a compiler that supports it, then you should not use it; because it won't comply with the standard(s) expected of a C compiler.
As I said before:
If you find a compiler that does do it, then the best thing to do is discard it; because it wouldn't be compliant with the standards.