I have the following problem:
I would like for a piece of code to be compiled only if a certain macro
has been defined AND has some specific value. Let me illustrate:
#ifdef SYMBOL
f() ;
#endif
will compile the f() line whenever SYMBOL is defined. Thus, if I have
compiled the file where all this stuff is contained with
-DSYMBOL=1
then f() will be compiled. It will also be compiled if I use
-DSYMBOL=
where no specific value follows the equal sign.
How can I arrange things so that f() does not get compiled in this latter
case? 7 2110
"Santa Claus" <sa***@NorthPol e.gov> wrote in message
news:pa******** *************** *****@NorthPole .gov... I have the following problem:
I would like for a piece of code to be compiled only if a certain macro has been defined AND has some specific value. Let me illustrate:
#ifdef SYMBOL f() ; #endif
will compile the f() line whenever SYMBOL is defined. Thus, if I have compiled the file where all this stuff is contained with
-DSYMBOL=1
then f() will be compiled. It will also be compiled if I use
-DSYMBOL=
where no specific value follows the equal sign.
How can I arrange things so that f() does not get compiled in this latter case?
#if SYMBOL == 1
include/define stuff..
#endif
On Wed, 01 Oct 2003 13:15:04 -0700, j wrote: "Santa Claus" <sa***@NorthPol e.gov> wrote in message news:pa******** *************** *****@NorthPole .gov... I have the following problem:
I would like for a piece of code to be compiled only if a certain macro has been defined AND has some specific value. Let me illustrate:
#ifdef SYMBOL f() ; #endif
will compile the f() line whenever SYMBOL is defined. Thus, if I have compiled the file where all this stuff is contained with
-DSYMBOL=1
then f() will be compiled. It will also be compiled if I use
-DSYMBOL=
where no specific value follows the equal sign.
How can I arrange things so that f() does not get compiled in this latter case?
#if SYMBOL == 1 include/define stuff.. #endif
Thanks for your reply, but that's not it. I need to compile if SYMBOL is
defined and has some value - any value. The problem is that by doing
-DSYMBOL= (or -DSYMBOL) no specific value seems to be substituted for
SYMBOL. That is, -DSYMBOL defines SYMBOL, but doesn't assign any value to
it.
Santa Claus <sa***@NorthPol e.gov> wrote in
news:pa******** *************** *****@NorthPole .gov: I would like for a piece of code to be compiled only if a certain macro has been defined AND has some specific value. Let me illustrate:
#ifdef SYMBOL f() ; #endif
will compile the f() line whenever SYMBOL is defined. Thus, if I have compiled the file where all this stuff is contained with
-DSYMBOL=1
then f() will be compiled. It will also be compiled if I use
-DSYMBOL=
where no specific value follows the equal sign.
How can I arrange things so that f() does not get compiled in this latter case?
#if SYMBOL == 1 include/define stuff.. #endif
Thanks for your reply, but that's not it. I need to compile if SYMBOL is defined and has some value - any value. The problem is that by doing -DSYMBOL= (or -DSYMBOL) no specific value seems to be substituted for SYMBOL. That is, -DSYMBOL defines SYMBOL, but doesn't assign any value to it.
What about
#if defined(SYMBOL) && SYMBOL
f();
#endif
--
- Mark ->
--
On Wed, 01 Oct 2003 19:32:44 +0000, Mark A. Odell wrote: Santa Claus <sa***@NorthPol e.gov> wrote in news:pa******** *************** *****@NorthPole .gov:
I would like for a piece of code to be compiled only if a certain macro has been defined AND has some specific value. Let me illustrate:
#ifdef SYMBOL f() ; #endif
will compile the f() line whenever SYMBOL is defined. Thus, if I have compiled the file where all this stuff is contained with
-DSYMBOL=1
then f() will be compiled. It will also be compiled if I use
-DSYMBOL=
where no specific value follows the equal sign.
How can I arrange things so that f() does not get compiled in this latter case?
#if SYMBOL == 1 include/define stuff.. #endif
Thanks for your reply, but that's not it. I need to compile if SYMBOL is defined and has some value - any value. The problem is that by doing -DSYMBOL= (or -DSYMBOL) no specific value seems to be substituted for SYMBOL. That is, -DSYMBOL defines SYMBOL, but doesn't assign any value to it.
What about
#if defined(SYMBOL) && SYMBOL f(); #endif
I am afraid that doesn't do it either. If SYMBOL is defined but has no
value then the if clause will evaluate to something illegal, for there
will be nothing to the right of the && operator.
Boy, this is an annoying issue!
On Wed, 01 Oct 2003 20:02:18 +0000, Santa Claus wrote: On Wed, 01 Oct 2003 19:32:44 +0000, Mark A. Odell wrote:
Santa Claus <sa***@NorthPol e.gov> wrote in news:pa******** *************** *****@NorthPole .gov:
> I would like for a piece of code to be compiled only if a certain > macro has been defined AND has some specific value. Let me illustrate: > > #ifdef SYMBOL > f() ; > #endif > > will compile the f() line whenever SYMBOL is defined. Thus, if I have > compiled the file where all this stuff is contained with > > -DSYMBOL=1 > > then f() will be compiled. It will also be compiled if I use > > -DSYMBOL= > > where no specific value follows the equal sign. > > How can I arrange things so that f() does not get compiled in this > latter case?
#if SYMBOL == 1 include/define stuff.. #endif
Thanks for your reply, but that's not it. I need to compile if SYMBOL is defined and has some value - any value. The problem is that by doing -DSYMBOL= (or -DSYMBOL) no specific value seems to be substituted for SYMBOL. That is, -DSYMBOL defines SYMBOL, but doesn't assign any value to it.
What about
#if defined(SYMBOL) && SYMBOL f(); #endif
I am afraid that doesn't do it either. If SYMBOL is defined but has no value then the if clause will evaluate to something illegal, for there will be nothing to the right of the && operator.
Boy, this is an annoying issue!
In case anybody is in the same predicament, I have been given a solution
that works for me.
First, there is a difference between
-DSYMBOL
and
-DSYMBOL=
The first one, -DSYMBOL, makes SYMBOL equal to 1. This is not the case I
am interested in. -DSYMBOL= is. In this case, SYMBOL seems to be
blank. One can proceed as follows:
#if ((SYMBOL - 1) == -1)
#undef SYMBOL
#endif
This works because I know that, whenever there is something non-blank
following the = sign in -DSYMBOL=, it will always be 0 or a positive
integer.
On Wed, 1 Oct 2003, Santa Claus wrote: On Wed, 01 Oct 2003 19:32:44 +0000, Mark A. Odell wrote: Santa Claus <sa***@NorthPol e.gov> wrote in
> I would like for a piece of code to be compiled only if a certain > macro has been defined AND has some specific value.
What about
#if defined(SYMBOL) && SYMBOL f(); #endif
I am afraid that doesn't do it either. If SYMBOL is defined but has no value then the if clause will evaluate to something illegal, for there will be nothing to the right of the && operator.
Check the Google Groups archive for this newsgroup.
This issue has come up many times before. IIRC, the
most portable way of doing it is to write
#if (SYMBOL-0 == 42)
f();
#endif
but you'd better check the archives first. Basically, a lot
of preprocessors do this in slightly different ways. I don't
know what the current C standard says, nor whether it differs
from C89.
Of course, the easiest thing to do is just to write
#ifdef SYMBOL
#if (SYMBOL == 42)
f();
#endif
#endif
....but why would you ever want to take the *easy* way out when
there's a complicated, obscure, and potentially non-portable
way?
-Arthur
In article <pa************ *************** *@NorthPole.gov >,
Santa Claus <sa***@NorthPol e.gov> wrote: I have the following problem:
I would like for a piece of code to be compiled only if a certain macrohas been defined AND has some specific value. Let me illustrate:
#ifdef SYMBOL f() ; #endif
will compile the f() line whenever SYMBOL is defined. Thus, if I have compiled the file where all this stuff is contained with
-DSYMBOL=1
then f() will be compiled. It will also be compiled if I use
-DSYMBOL=
where no specific value follows the equal sign.
How can I arrange things so that f() does not get compiled in this latter case?
#define cat(x,y) x ## y
#define xcat(x,y) cat(x,y)
#if !defined(SYMBOL )
you did not define "SYMBOL"
#elif xcat(SYMBOL,1) == 1
you said -DSYMBOL=
#elif xcat(SYMBOL,1) == 11
you said -DSYMBOL or -DSYMBOL=1
#else
you said -DSYMBOL=somethi ngelse
#endif
--
Rouben Rostamian <ro*******@umbc .edu> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sabyasachi Basu |
last post by:
While trying to port some stuff from Unix to Windows, I encountered a
strange behaviour of function macros with empty arguments. Here is a small
snippet which illustrates the problem:
#include <iostream>
#include <string>
using namespace std;
#define B(X, Y) Y
|
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
|
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;
|
by: Sune |
last post by:
Hi,
previously I used Eclipse CDT for compiling my files just to get
started with C and leave C++ behind. Now it's time to get a little more
serious so I've moved my files to a new workplace and begun to use GNU
Autotools. I'm sorry to say I'm new to gcc as well :(
Now I get the most ridiculous compile error which I'm unable to solve.
Can someone, please, help me with this? gcc output together with the
files mentioned in the gcc error...
|
by: richardlang |
last post by:
Anyone out there ever come across a preprocessor macro that compares an
argument value against the predefined __DATE__ macro in order to
control conditional compilation based on date.
Something along the lines of...
# define DateLaterThan(x) ...
that could be used for things like
| |
by: ezmeralda |
last post by:
Hello,
I have some code which shall be compiled in .NET v1.1 and v2.0 but
which
has to be different for the two .NET-Versions.
Therefore I need to use a construct like
#if NET_20
<2.0 specific code>
|
by: Gowtham |
last post by:
Hi, I am trying to write some code which acts differently when
compiled on
32 bit and 64 bit machines. To identify the machine type, I am trying
to find
the sizeof( int ) and comparing it with 32 and 64.
But, the compiler is complaining about syntax errors in the #if lines.
Errors:
32-64.cpp:7:13: missing binary operator before '('
|
by: Rohit |
last post by:
Hi,
I am working on a switch module which after reading voltage through a
port pin and caterogizing it into three ranges(open,low or high),
passes this range to a function switch_status() with parameters value
and signal ID. Signal Id is used to get a user configurable parameter
inside a configuration file, which depends on the type of switch.
I have implemented it as under. Please ignore those magic numbers as I
have mimized logic to...
|
by: congot |
last post by:
How to verify a preprocessor macros defined with no value , and only if defined with a value should the code within that be exectued.
#ifdef ABC
int a;
#endif
int a is available only if a value of ABC is available.
ABC is defined as
#define ABC
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |