473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Determining whether a macro has been defined

Are these two lines equivalent?

#ifdef MACRO

#if MACRO==0

Jul 23 '05 #1
8 1725
BigMan wrote:
Are these two lines equivalent?

#ifdef MACRO

#if MACRO==0


No. Why would they be? If 'MACRO' is defined as

#define MACRO 2

the first variant will "evaluate" to 'true', while the second one - to
'false'.

--
Best regards,
Andrey Tarasevich
Jul 23 '05 #2
gb
No. The first one evalutes to true only if MACRO has been defined
(regardless of its definition). The second evalutes to true if either
of these is true:

MACRO is undefined
MACRO is defined but evalutes at compile time to 0.

See section 16.1.4 in the standard.

Gregg

Jul 23 '05 #3
Ooops, I've put it the wrong way. Here's what I mean: does it matter
which line I use to check if a macro has been defined.

Jul 23 '05 #4

BigMan wrote:
Ooops, I've put it the wrong way. Here's what I mean: does it matter
which line I use to check if a macro has been defined.


Yes, it matters. Didn't you read the other posts? The first way is
correct.
Brian

Jul 23 '05 #5
Default User wrote:
BigMan wrote:
Ooops, I've put it the wrong way. Here's what I mean: does it matter
which line I use to check if a macro has been defined.

Yes, it matters. Didn't you read the other posts? The first way is
correct.

If he doesn't want to worry about the case where it is defined and is zero.
It doesn't matter.
Jul 23 '05 #6

Ron Natalie wrote:
Default User wrote:
BigMan wrote:
Ooops, I've put it the wrong way. Here's what I mean: does it matterwhich line I use to check if a macro has been defined.

Yes, it matters. Didn't you read the other posts? The first way is
correct.

If he doesn't want to worry about the case where it is defined and is

zero. It doesn't matter.


I don't recall that in his problem description.
Brian

Jul 23 '05 #7
BigMan wrote:
Ooops, I've put it the wrong way. Here's what I mean: does it matter
which line I use to check if a macro has been defined.


Yes it does. The former method (with '#ifdef') checks whether it has
been defined. The latter one (with '#if') checks whether it is
substituted with integral zero (if well-formed). This is not the same.

For example, defining 'MACRO' as either '0' or '1' will give you the
same results from the former method (i.e. '#ifdef' will say that it is
defined in both cases), but different results from the latter method.

Defining 'MACRO' as follows

#define MACRO

will work with the former method, but it makes the latter one ill-formed.

--
Best regards,
Andrey Tarasevich
Jul 23 '05 #8
Thanks to all of you! I think I got it.

Jul 23 '05 #9

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

Similar topics

12
by: Cliff Wells | last post by:
Hi, I'm writing an application that needs to know if an Internet connection is available. Basically, I want to have something similar to what a lot of email clients have, where the app can work...
2
by: foo | last post by:
I'm creating a debug class called debug_mem_allocation for the purpose of finding memory leaks. I used macro's to replace the new and delete operators. My problem is with trying to replace the...
2
by: Luca | last post by:
I have the following problem: I'm developing a system where there are some processes that communicate each other via message queues; the message one process can send to another process is as...
5
by: Ken | last post by:
Hi. This is a followup to my NULL macro vs. 0 question. It's in a separate thread, because I need to post using google, so my original thread isn't available to me yet :(. Anyway, I just...
7
by: Newbie_sw2003 | last post by:
Where should I use them? I am giving you my understandings. Please correct me if I am wrong: MACRO: e.g.:#define ref-name 99 The code is substituted by the MACRO ref-name. So no overhead....
10
by: Orion | last post by:
Hey, I was wondering if it was possible to determine if you hit 'EOF' using fseek? I'm using fseek to traverse through the file from start to end and capturing the data into a linked list...
1
by: Casanova | last post by:
Hello!!! I have been using C for a very short while. I am used to macros in C, but while i was reading the code for LittleOS (an open source OS), i came across a type of macro wherein no value...
44
by: Simon Morgan | last post by:
Hi, Can somebody please help me grok the offsetof() macro? I've found an explanation on http://www.embedded.com/shared/printableArticle.jhtml?articleID=18312031 but I'm afraid it still...
12
by: shyam | last post by:
Hi all is there any way the determine which function currently is executing in a process ? For example we can find the file name using __FILE__ and line number using __LINE__ macros ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
isladogs
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...

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.