Macro substitution and runtime question.

C

Chad

This is taken from page 90 in "The C Programming Language" by Kernighan
and Richtie.

They have the debugging print macro:

#define dprint(expr) printf(#expr " = %g \n", expr)

Which is invoked as in:

dprint(x/y);

The question is, does dprint(x/y) get expanded every time the program
is run (ie I compile it once, but run the program like 200 times), or
only once when the program gets compiled?
 
M

Mike Wahler

Chad said:
This is taken from page 90 in "The C Programming Language" by Kernighan
and Richtie.

They have the debugging print macro:

#define dprint(expr) printf(#expr " = %g \n", expr)

Which is invoked as in:

dprint(x/y);

The question is, does dprint(x/y) get expanded every time the program
is run (ie I compile it once, but run the program like 200 times), or
only once when the program gets compiled?

All preprocessing tokens are translated at compile time.

-Mike
 
C

Chad

Mike said:
All preprocessing tokens are translated at compile time.

-Mike

So in other words, the expression dprint(x/y) doesn't get expanded
every time I run the program?
 
S

Singamsetty

Chad said:
So in other words, the expression dprint(x/y) doesn't get expanded
every time I run the program?

.......yes, before actual compilation, the C preprocessor replaces all
"dprint(expr)" statements with printf(#expr " = %g \n", expr). So it
has nothing to do with runtime.

- Singamsetty
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top