On macros

N

Nickolai Leschov

Hello all,

When I define a macro like this,

#define MJOR_VERS 6 // Major version number

does the value of a macro include the comment too?

Regards,
Nickolai Leschov
 
E

Eric Sosman

Nickolai said:
Hello all,

When I define a macro like this,

#define MJOR_VERS 6 // Major version number

does the value of a macro include the comment too?

No.
 
R

Richard Heathfield

Nickolai Leschov said:
Hello all,

When I define a macro like this,

#define MJOR_VERS 6 // Major version number

does the value of a macro include the comment too?

Eric has already answered this, but in case you want to know why the
comment is not preserved, the answer is that comments are removed in
Translation Phase 3, whereas macro expansions don't occur until
Translation Phase 4. Even in implementations where things aren't done in
precisely that order, the end result must be as if they had. Thus, the
Standard guarantees that the comment will not survive.
 
E

Eric Sosman

Richard said:
Nickolai Leschov said:


Eric has already answered this, but in case you want to know why the
comment is not preserved, the answer is that comments are removed in
Translation Phase 3, whereas macro expansions don't occur until
Translation Phase 4. Even in implementations where things aren't done in
precisely that order, the end result must be as if they had. Thus, the
Standard guarantees that the comment will not survive.

... which in turn raises the question of why the
translation phases are defined in this particular way.
The best answer I have for that question is that the
preprocessor is not really a manipulator of text, but
a manipulator of tokens[*] that are extracted from
the text. The tokens in the given definition are

#
define
MAJOR_VERS
6

.... and that's all: Comments, like other forms of
white space, are not tokens.

[*] "Preprocessing tokens," actually; the Standard
found it necessary to distinguish between the tokens
the preprocessor works on and those that the later
compilation phases work with.
 
N

Nickolai Leschov

Eric said:
... which in turn raises the question of why the
translation phases are defined in this particular way.
The best answer I have for that question is that the
preprocessor is not really a manipulator of text, but
a manipulator of tokens[*] that are extracted from
the text. The tokens in the given definition are

#
define
MAJOR_VERS
6

... and that's all: Comments, like other forms of
white space, are not tokens.

Thank you very much for your answer.
 
N

Nickolai Leschov

Richard said:
Eric has already answered this, but in case you want to know why the
comment is not preserved, the answer is that comments are removed in
Translation Phase 3, whereas macro expansions don't occur until
Translation Phase 4. Even in implementations where things aren't done in
precisely that order, the end result must be as if they had. Thus, the
Standard guarantees that the comment will not survive.
Thank you. You really make things clear.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top