Meanings of macro

M

mangesh

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 .
 
R

Rolf Magnus

mangesh said:
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.
 
F

Frederick Gotham

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top