<- Chameleon -> wrote:
I have a preprocessor constant (SUPPORT_PNG_IM AGE) with 3 states, to control the compilation:
---------
#undef SUPPORT_PNG_IMA GE
#define SUPPORT_PNG_IMA GE
#define SUPPORT_PNG_IMA GE ONLY
---------
With the 1st & 3rd line the following line works
---------
#if SUPPORT_PNG_IMA GE == ONLY
---------
but with the 2nd, compiler throws:
---------
fatal error C1017: invalid integer constant expression
---------
how can I handle this?
...
I assume that 'ONLY' is not #defined anywhere. Right?
In the first case (when 'SUPPORT_PNG_IM AGE' is not defined) the
preprocessor replaces both 'SUPPORT_PNG_IM AGE' and 'ONLY' with '0',
which means that your '#if' will turn into
#if 0 == 0
In the second case (when 'SUPPORT_PNG_IM AGE' is defined as nothing),
your '#if' will turn into
#if == 0
In the third case after full replacement you'll again end up with
#if 0 == 0
Note, that the second variant is invalid (that's what causes the error).
Not also that the first and the third variant produce the same result.
Maybe you should try to do something like this instead
#define SPI_NONE 0
#define SPI_ONLY 1
#define SPI_ALL 2
then do
#define SUPPORT_PNG_IMA GE SPI_ONLY // or SPI_NONE, or SPI_ALL
and implement the '#if' as follows
#if SUPPORT_PNG_IMA GE == SPI_ONLY
...
or
#if SUPPORT_PNG_IMA GE < SPI_ALL
...
etc.
--
Best regards,
Andrey Tarasevich