473,608 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

preprocessor

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?

thanks
Jul 22 '05 #1
2 4872
On Sat, 28 Feb 2004 03:55:05 +0200, "<- Chameleon ->"
<ch******@hotma il.NOSPAM.com> 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'd suggest sticking with one of the following conventions or the other for
defining SUPPORT_PNG_IMA GE:

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_IMA GE
#ifndef SUPPORT_PNG_IMA GE
#if defined(SUPPORT _PNG_IMAGE)
#if !defined(SUPPOR T_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(SUPPOR T_PNG_IMAGE) // your 1st case

#if defined(SUPPORT _PNG_IMAGE) && \
SUPPORT_PNG_IMA GE != ONLY // case 2

#if defined(SUPPORT _PNG_IMAGE) && \
SUPPORT_PNG_IMA GE == 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
<- 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

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

205
10554
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
24
40152
by: Nudge | last post by:
I have an array, and an unrolled loop which looks like this: do_something(A); do_something(A); .... do_something(A); I thought: why should I type so much? I should write a macro. So I was looking to write something along the lines of:
16
4482
by: Trying_Harder | last post by:
Is it possible to redefine a macro with global scope after undefining it in a function? If yes, could someone explain how? /If/ my question above isn't very clear you can refer to the following example. eg cosider 2 files sample.c and sample.h sample.h
13
3577
by: seemanta dutta | last post by:
Greetings C gurus, I have used preprocessor directives since a very long time. But whenever I see some professional piece of C code, the linux kernel for example, I get literally confused by the amount of preprocessor directives used in these code. Can anyone please tell me how to actually use these preprocessor directives in a more professional way like selecting particular lines of code suited for some particular hardware etc...
18
3017
by: /* frank */ | last post by:
My teacher said that array in C is managed by preprocessor. Preprocesser replace all array occurences (i.e. int a ) with something that I don't understand/remember well. What's exactly happens with array during preprocessing/compiling stage? Thanks in advance
13
2114
by: Chris Croughton | last post by:
Is the following code standard-compliant, and if so what should it do? And where in the standard defines the behaviour? #include <stdio.h> #define DEF defined XXX int main(void) { int defined = 2;
9
3651
by: Walter Roberson | last post by:
I have run into a peculiarity with SGI's C compiler (7.3.1.2m). I have been reading carefully over the ANSI X3.159-1989 specification, but I cannot seem to find a justification for the behaviour. Could someone point me to the appropriate section, or else confirm the behaviour as a bug? For a particular project, I am using the C preprocessor phase only. I am not using the standalone program 'cpp' because proper functioning of my project...
2
6633
by: Paolo | last post by:
I imported a VC++6.0 project into VC++7.1. The conversion operation makes a mess with Preprocessor Definitions, adding a "$(NoInherit)" for each file. For example: I had a DLL project in VC++6.0 where the definitions were: _UNICODE,_DEBUG,_WIN32_DCOM,WIN32,_WINDOWS,_WINDLL,_AFXDLL,_USRDLL In VC++7.1, these are the preprocessor definitions of the project (right-click the project in Solution Explorer and choose Properties -> C++ ->...
32
2766
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input the same file ? If not then how much variation is allowed ? Is it just a bit more or less white space here and there or could could there be larger differences ? If the output is not deterministic then is it possible that the output of the...
31
2902
by: Sam of California | last post by:
Is it accurate to say that "the preprocessor is just a pass in the parsing of the source file"? I responded to that comment by saying that the preprocessor is not just a pass. It processes statements that the compiler does not process. The good people in the alt.comp.lang.learn.c-c++ newsgroup insist that the preprocessor is just one of many passes. The preprocessor processes a grammer unique to the preprocessor and only that grammer. ...
0
8087
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8509
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8493
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8365
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6847
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5499
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4053
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2493
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1620
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.