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

Discussion in 'C++' started by Jacek Dziedzic, Jul 22, 2003.

  1. .... making things like

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

    valid? Or not?

    - J.
     
    Jacek Dziedzic, Jul 22, 2003
    #1
    1. Advertising

  2. On Tue, 22 Jul 2003 19:25:21 +0200, "Jacek Dziedzic" <> wrote:

    >... 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.
     
    Alf P. Steinbach, Jul 22, 2003
    #2
    1. Advertising

  3. "Alf P. Steinbach" <> wrote...
    > On Tue, 22 Jul 2003 19:25:21 +0200, "Jacek Dziedzic"

    <> wrote:
    >
    > >... 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.


    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
     
    Victor Bazarov, Jul 22, 2003
    #3
  4. On Tue, 22 Jul 2003 13:59:32 -0400, "Victor Bazarov" <> wrote:

    >"Alf P. Steinbach" <> wrote...
    >> On Tue, 22 Jul 2003 19:25:21 +0200, "Jacek Dziedzic"

    ><> wrote:
    >>
    >> >... 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.

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


    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
     
    Alf P. Steinbach, Jul 22, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cronus
    Replies:
    1
    Views:
    708
    Paul Mensonides
    Jul 15, 2004
  2. Replies:
    0
    Views:
    1,167
  3. Nalla
    Replies:
    25
    Views:
    917
    MikeyD
    Oct 8, 2003
  4. Monk
    Replies:
    10
    Views:
    1,521
    Michael Wojcik
    Apr 20, 2005
  5. Subra

    gcc Preprocessor (-E) with comments

    Subra, Jun 8, 2007, in forum: C Programming
    Replies:
    2
    Views:
    438
    Subra
    Jun 8, 2007
Loading...

Share This Page