By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,301 Members | 1,366 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,301 IT Pros & Developers. It's quick & easy.

preprocessor

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Sat, 28 Feb 2004 03:55:05 +0200, "<- Chameleon ->"
<ch******@hotmail.NOSPAM.com> wrote:
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


thanks


Leor Zolman
BD Software
le**@bdsoft.com
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
Jul 22 '05 #2

P: n/a
<- Chameleon -> wrote:
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

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.