473,408 Members | 2,734 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,408 software developers and data experts.

How does #define operate ?

Hello

If I say

#define MASK 0x00F0
#define BIT_SET MASK
#define MASK 0x000F

than what value will BIT_SET macro expand to ?
I mean the preprocessor does lasy evaluation or immediate evaluation ?
I tryed to figure it out from MSDN once but I couldn't

Thank you
Timothy Madden
Romania
----------------------------------------------------------------------------
And I don't wanna miss a thing
Jul 22 '05 #1
5 1721

"Timothy Madden" <ba****@rmv.spam.home.ro> wrote in message
news:2r*************@uni-berlin.de...
Hello

If I say

#define MASK 0x00F0
#define BIT_SET MASK
#define MASK 0x000F

than what value will BIT_SET macro expand to ?
I mean the preprocessor does lasy evaluation or immediate evaluation ?
I tryed to figure it out from MSDN once but I couldn't


I don't think the standard deals with preprocessor stuff, but on my compiler
it gives me a redefinition error. If I want to re-#define something, I have
to #undef it first. Which would imply (assuming you threw in a #undef MASK
before the second #define) that BIT_SET would still be 0x00F0, because
otherwise what would the point be of requiring #undef? I see several places
where something is defined just before including a file that needs it, then
undefined so as not to interfere with other, later, includes.

-Howard
Jul 22 '05 #2

"Howard" <al*****@hotmail.com> wrote in message
news:bD********************@bgtnsc05-news.ops.worldnet.att.net...

"Timothy Madden" <ba****@rmv.spam.home.ro> wrote in message
news:2r*************@uni-berlin.de...
Hello

If I say

#define MASK 0x00F0
#define BIT_SET MASK
#define MASK 0x000F

than what value will BIT_SET macro expand to ?
I mean the preprocessor does lasy evaluation or immediate evaluation ?
I tryed to figure it out from MSDN once but I couldn't

I don't think the standard deals with preprocessor stuff, but on my

compiler it gives me a redefinition error. If I want to re-#define something, I have to #undef it first. Which would imply (assuming you threw in a #undef MASK before the second #define) that BIT_SET would still be 0x00F0, because
otherwise what would the point be of requiring #undef? I see several places where something is defined just before including a file that needs it, then undefined so as not to interfere with other, later, includes.

-Howard


Not true, BIT_SET expands to MASK, not 0x00F0. If you redefine MASK, your
redefine BIT_SET.

DrX
Jul 22 '05 #3

"Xenos" <do**********@spamhate.com> wrote in message
news:cj*********@cui1.lmms.lmco.com...

"Howard" <al*****@hotmail.com> wrote in message
news:bD********************@bgtnsc05-news.ops.worldnet.att.net...

"Timothy Madden" <ba****@rmv.spam.home.ro> wrote in message
news:2r*************@uni-berlin.de...
Hello

If I say

#define MASK 0x00F0
#define BIT_SET MASK
#define MASK 0x000F

than what value will BIT_SET macro expand to ?
I mean the preprocessor does lasy evaluation or immediate evaluation ?
I tryed to figure it out from MSDN once but I couldn't

I don't think the standard deals with preprocessor stuff, but on my

compiler
it gives me a redefinition error. If I want to re-#define something, I

have
to #undef it first. Which would imply (assuming you threw in a #undef

MASK
before the second #define) that BIT_SET would still be 0x00F0, because
otherwise what would the point be of requiring #undef? I see several

places
where something is defined just before including a file that needs it,

then
undefined so as not to interfere with other, later, includes.

-Howard


Not true, BIT_SET expands to MASK, not 0x00F0. If you redefine MASK,

your redefine BIT_SET.

DrX


You're correct (at least using CodeWarrior on the Mac).

And it's obvious why. My thinking was backwards. At the time/place of
expansion, it evaluates the symbol, and by that time the symbol has changed.

(But I definitely do need to #undef it before I can #define it again.)

-Howard


Jul 22 '05 #4

"Howard" <al*****@hotmail.com> wrote in message
news:VB*********************@bgtnsc05-news.ops.worldnet.att.net...

"Xenos" <do**********@spamhate.com> wrote in message
news:cj*********@cui1.lmms.lmco.com...

"Howard" <al*****@hotmail.com> wrote in message
news:bD********************@bgtnsc05-news.ops.worldnet.att.net...

"Timothy Madden" <ba****@rmv.spam.home.ro> wrote in message
news:2r*************@uni-berlin.de...
> Hello
>
> If I say
>
> #define MASK 0x00F0
> #define BIT_SET MASK
> #define MASK 0x000F
>
> than what value will BIT_SET macro expand to ?
> I mean the preprocessor does lasy evaluation or immediate evaluation ? > I tryed to figure it out from MSDN once but I couldn't
>

I don't think the standard deals with preprocessor stuff, but on my compiler
it gives me a redefinition error. If I want to re-#define something,
I have
to #undef it first. Which would imply (assuming you threw in a #undef

MASK
before the second #define) that BIT_SET would still be 0x00F0, because
otherwise what would the point be of requiring #undef? I see several

places
where something is defined just before including a file that needs it,

then
undefined so as not to interfere with other, later, includes.

-Howard


Not true, BIT_SET expands to MASK, not 0x00F0. If you redefine MASK,

your
redefine BIT_SET.

DrX


You're correct (at least using CodeWarrior on the Mac).

And it's obvious why. My thinking was backwards. At the time/place of
expansion, it evaluates the symbol, and by that time the symbol has

changed.
(But I definitely do need to #undef it before I can #define it again.)


Actualy I really meant:

#define MASK 0x00F0
#define BIT_SET MASK
#undef MASK
#define MASK 0x000F

Should the standard not say something about this ?
Could MASK in turn be defined as some other defined symbol ? How many levels
can this go ? Why does any book not say anything about it ?
Anyone can tell me how other compilers behave ?

Thank you
Timothy Madden
Romania
-------------------------------------------------
And I don't wanna miss a thing
Jul 22 '05 #5

"Timothy Madden" <ba****@rmv.spam.home.ro> wrote in message
news:2r*************@uni-berlin.de...

Actualy I really meant:

#define MASK 0x00F0
#define BIT_SET MASK
#undef MASK
#define MASK 0x000F

Should the standard not say something about this ?
Could MASK in turn be defined as some other defined symbol ? How many levels can this go ? Why does any book not say anything about it ?
Anyone can tell me how other compilers behave ?

It's not the compiler, but the preprocessor. They behave by following the
standard. You are not setting one variable equal to another. You are
telling the preprocessor that the macro BIT_SET is equal to the the text
"MASK" (without the quotes). After the text replacement, the code will be
rescanned looking for more macros. If MASK is defined when this is done,
then MASK will be replaced. If not, it will be passed as is to the
compiler.

DrX
Jul 22 '05 #6

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

Similar topics

6
by: Mats-Lennart Hansson | last post by:
Hi, Is there a way to define where the assembly should search for its referenced assemblies? I have my assemblies in different locations and I don't want to add them the GAC. Any help is...
13
by: momobear | last post by:
hi, is there a way to let python operate on sequence of int or short? In C, we just need declare a point, then I could get the point value, just like: short* k = buffer, //k is a point to a...
45
by: salad | last post by:
I'm curious about your opinion on setting relationships. When I designed my first app in Access I'd go to Tools/Relationships and set the relationships. Over time I'd go into the window and see...
8
by: mailursubbu | last post by:
Hi, Will it be possible to #define a char pointer... It means if write some thing like #define CHAR_PTR (char *) // I know this wont work I should be able to use CHAR_PTR to define a...
69
by: RC | last post by:
I know how to do this in JavaScript by window.open("newFile.html", "newTarget", "scrollbars=no,resizable=0,width=200,height=200"); The browser will open a new window size 200x200, not allow...
17
by: niraj.tiwari | last post by:
What is meaning of the following define:- #define x(argl...) x1(##argl)
1
by: newbie | last post by:
Here is my question: I want to have a class, which requires a typename T with interface "operate()" and "Init()" as its parameter. template <class Tclass Foo { public: Foo(int param) {...
3
by: qianz99 | last post by:
Hi I am not sure what this code does. I have the following questions 1. where is the case? 2. #define TLV_INTEGER(name, octets) p->name = -1; Is it define a function TLV_INTEGER(name, octets) ...
8
by: Jerry Spence1 | last post by:
Do Timers operate on the UI thread, or do they have it's own thread? I'm trying to assess the pros and cons for using a timer or a thread for a certain application. -Jerry
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
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,...
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.