 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Sat Feb 28, 2004 1:55 am Post subject: preprocessor |
|
|
I have a preprocessor constant (SUPPORT_PNG_IMAGE) with 3 states, to control the compilation:
---------
#undef SUPPORT_PNG_IMAGE
#define SUPPORT_PNG_IMAGE
#define SUPPORT_PNG_IMAGE ONLY
---------
With the 1st & 3rd line the following line works
---------
#if SUPPORT_PNG_IMAGE == ONLY
---------
but with the 2nd, compiler throws:
---------
fatal error C1017: invalid integer constant expression
---------
how can I handle this?
thanks
|
|
| Back to top |
|
 |
Leor Zolman Guest
|
Posted: Sat Feb 28, 2004 2:32 am Post subject: Re: preprocessor |
|
|
On Sat, 28 Feb 2004 03:55:05 +0200, "<- Chameleon ->"
<cham_gss (AT) hotmail (DOT) NOSPAM.com> wrote:
| Quote: | I have a preprocessor constant (SUPPORT_PNG_IMAGE) with 3 states, to control the compilation:
---------
#undef SUPPORT_PNG_IMAGE
#define SUPPORT_PNG_IMAGE
#define SUPPORT_PNG_IMAGE ONLY
---------
With the 1st & 3rd line the following line works
---------
#if SUPPORT_PNG_IMAGE == ONLY
---------
but with the 2nd, compiler throws:
---------
fatal error C1017: invalid integer constant expression
---------
how can I handle this?
|
I'd suggest sticking with one of the following conventions or the other for
defining SUPPORT_PNG_IMAGE:
Convention #1: Either it is defined or it isn't.
Convention #2: It has a non-empty value, and we'll be testing it.
The first convention, testable with any of the following:
#ifdef SUPPORT_PNG_IMAGE
#ifndef SUPPORT_PNG_IMAGE
#if defined(SUPPORT_PNG_IMAGE)
#if !defined(SUPPORT_PNG_IMAGE)
is good enough for either/or situations. The second, testable with
#if SYMBOL == whatever
is suitable for having many mutually exclusive conditional compilation
blocks.
You /can/ get where you want to go with the convention you've already
established, if you absolutely have to:
#if !defined(SUPPORT_PNG_IMAGE) // your 1st case
#if defined(SUPPORT_PNG_IMAGE) &&
SUPPORT_PNG_IMAGE != ONLY // case 2
#if defined(SUPPORT_PNG_IMAGE) &&
SUPPORT_PNG_IMAGE == ONLY // case 3
but it is not very orthogonal. BTW, ONLY has been previously #defined,
right?
-leor
Leor Zolman
BD Software
[email]leor (AT) bdsoft (DOT) com[/email]
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html
|
|
| Back to top |
|
 |
Andrey Tarasevich Guest
|
Posted: Sat Feb 28, 2004 2:57 am Post subject: Re: preprocessor |
|
|
<- Chameleon -> wrote:
| Quote: | I have a preprocessor constant (SUPPORT_PNG_IMAGE) with 3 states, to control the compilation:
---------
#undef SUPPORT_PNG_IMAGE
#define SUPPORT_PNG_IMAGE
#define SUPPORT_PNG_IMAGE ONLY
---------
With the 1st & 3rd line the following line works
---------
#if SUPPORT_PNG_IMAGE == 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_IMAGE' is not defined) the
preprocessor replaces both 'SUPPORT_PNG_IMAGE' and 'ONLY' with '0',
which means that your '#if' will turn into
#if 0 == 0
In the second case (when 'SUPPORT_PNG_IMAGE' 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_IMAGE SPI_ONLY // or SPI_NONE, or SPI_ALL
and implement the '#if' as follows
#if SUPPORT_PNG_IMAGE == SPI_ONLY
...
or
#if SUPPORT_PNG_IMAGE < SPI_ALL
...
etc.
--
Best regards,
Andrey Tarasevich
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|