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

Meanings of macro

P: n/a
I have some macros defined in code like

#define ISF (0)
#define ISC (1 << 0)

How are the interpreted ?
I can understand
#define ONE 1

But not first 2 macros , can anyone explain ?

Regards ,
Mangesh .

Oct 3 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
mangesh wrote:
I have some macros defined in code like

#define ISF (0)
#define ISC (1 << 0)

How are the interpreted ?
I can understand
#define ONE 1

But not first 2 macros , can anyone explain ?
A macro is simply a name and a piece of text that - before actual
compilation - will get inserted in your program wherever you use the name.

So if you write:

x = ISF;
y = ISC;

the preprocessor turns it into:

x = (0);
y = (1 << 0);

and the meaning of this doesn't have anything to do with macros anymore.

Oct 3 '06 #2

P: n/a
mangesh posted:
I have some macros defined in code like

#define ISF (0)
#define ISC (1 << 0)

How are the interpreted ?

Simple text substitution before the code is even compiled.

I can understand
#define ONE 1

But not first 2 macros , can anyone explain ?

Yes, it's simple text substitution. The following program:
#define ONE 1

#include <iostream>

int main()
{
std::cout << ONE << '\n';;
}

becomes:

#include <iostream>

int main()
{
std::cout << 1 << '\n';;
}

after the preprocessing stage. The compiler, g++, has the -E switch to show
you the preprocessor output.

--

Frederick Gotham
Oct 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.