are // comments legal at the ends of preprocessor lines?

J

Jacek Dziedzic

.... making things like

#endif // of the "#ifdef DEBUG" part

valid? Or not?

- J.
 
A

Alf P. Steinbach

... making things like

#endif // of the "#ifdef DEBUG" part

valid? Or not?

Except for multi-line macro definitions the answer is yes.

The answer for multi-line macro definitions can possibly be that
the standard is somewhat less than clear about the effect.

You can probably find more information about the issue (which
I've nearly forgot, just a vague recollection that there is an
issue) by using a search engine, or delving into the standard.
 
V

Victor Bazarov

Alf P. Steinbach said:
Except for multi-line macro definitions the answer is yes.

The answer for multi-line macro definitions can possibly be that
the standard is somewhat less than clear about the effect.

How is it "less than clear"? See 2.1 Phases of translation.
'2' happens earlier than '3', and those happen earlier than '4'.
So, a backslash+newline in a // comment makes the comment span
more than one line. Then the comment is replaced with a single
space character, and only after that the preprocessing directives
are executed.

So, by the time preprocessor gets its hands on the directives,
there are no more comments in the file.
You can probably find more information about the issue (which
I've nearly forgot, just a vague recollection that there is an
issue) by using a search engine, or delving into the standard.

I didn't know there was an issue...

Victor
 
A

Alf P. Steinbach

Alf P. Steinbach said:
How is it "less than clear"? See 2.1 Phases of translation.
'2' happens earlier than '3', and those happen earlier than '4'.
So, a backslash+newline in a // comment makes the comment span
more than one line. Then the comment is replaced with a single
space character, and only after that the preprocessing directives
are executed.

So, by the time preprocessor gets its hands on the directives,
there are no more comments in the file.


I didn't know there was an issue...

Neither did I until it was discussed either here or in
comp.lang.c++.moderated, I'm not sure. Seeing your comments I
think the issue was about __LINE__. But not sure...

Cheers,

- Alf
 

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,007
Latest member
obedient dusk

Latest Threads

Top