/* #include <someyhing.h> */ => include it or do not include it?That is the question ....

Discussion in 'C Programming' started by Andreas Bogenberger, Feb 21, 2008.

  1. Hi all,

    I stumbled on the following example:

    /*
    #include <something.h>
    #include <even_more.h>
    */

    gpp expands the #include statements. I'm not really sure how to interpret
    this correctly. As I got this like written above, I suppose it is working
    on an other platform. However, I have found nothing in 6.4.9, 6.4.7
    (however R3 mentions an undefined behavior if /* is between the braces or
    double quotes of the include directive) or 6.10 and I am getting to the
    conclusion that this is an undefined behavior. Is my assumption right?

    best regards,
    Andreas
    Andreas Bogenberger, Feb 21, 2008
    #1
    1. Advertising

  2. Re: /* #include <someyhing.h> */ => include it or do not include it? That is the question ....

    Andreas Bogenberger <> writes:

    > Hi all,
    >
    > I stumbled on the following example:
    >
    > /*
    > #include <something.h>
    > #include <even_more.h>
    > */
    >
    > gpp expands the #include statements.


    [What is gpp -- a typo for gcc?]

    > I'm not really sure how to interpret
    > this correctly.


    The standard lays out a sequence of translation phases that help make
    this clear. The implementation must behave as if it have these
    phases.

    The two that relate to the above are 3 and 4:

    3. The source file is decomposed into preprocessing tokens6) and
    sequences of white-space characters (including comments). A
    source file shall not end in a partial preprocessing token or in
    a partial comment. Each comment is replaced by one space
    character. New-line characters are retained. Whether each
    nonempty sequence of white-space characters other than new-line
    is retained or replaced by one space character is
    implementation-defined.

    4. Preprocessing directives are executed, macro invocations are
    expanded, and _Pragma unary operator expressions are executed. If
    a character sequence that matches the syntax of a universal
    character name is produced by token concatenation (6.10.3.3), the
    behavior is undefined. A #include preprocessing directive causes
    the named header or source file to be processed from phase 1
    through phase 4, recursively. All preprocessing directives are
    then deleted.

    It seems clear from this that phase 4 won't see any include directives
    in your example -- just a space where the comment was.

    > As I got this like written above, I suppose it is working
    > on an other platform. However, I have found nothing in 6.4.9, 6.4.7
    > (however R3 mentions an undefined behavior if /* is between the braces or
    > double quotes of the include directive) or 6.10 and I am getting to the
    > conclusion that this is an undefined behavior. Is my assumption
    > right?


    It is well-defined.

    --
    Ben.
    Ben Bacarisse, Feb 22, 2008
    #2
    1. Advertising

  3. Re: /* #include <someyhing.h> */ => include it or do not include it? That is the question ....

    Andreas Bogenberger <> writes:
    > I stumbled on the following example:
    >
    > /*
    > #include <something.h>
    > #include <even_more.h>
    > */
    >
    > gpp expands the #include statements. I'm not really sure how to interpret
    > this correctly. As I got this like written above, I suppose it is working
    > on an other platform. However, I have found nothing in 6.4.9, 6.4.7
    > (however R3 mentions an undefined behavior if /* is between the braces or
    > double quotes of the include directive) or 6.10 and I am getting to the
    > conclusion that this is an undefined behavior. Is my assumption right?


    If the code is exactly as you posted it, then the include directives
    are part of a comment and should be ignored.

    My best guess is that the code is not exactly as you posted it, that
    there's some subtle difference between the actual code and what you
    posted (perhaps something you assumed was insignificant).

    --
    Keith Thompson (The_Other_Keith) <>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Feb 22, 2008
    #3
  4. Re: /* #include <someyhing.h> */ => include it or do not includeit? That is the question ....

    On Thu, 21 Feb 2008 23:05:51 -0800, Keith Thompson wrote:

    > Andreas Bogenberger <> writes:
    >> I stumbled on the following example:
    >>
    >> /*
    >> #include <something.h>
    >> #include <even_more.h>
    >> */
    >>
    >> gpp expands the #include statements. I'm not really sure how to
    >> interpret this correctly. As I got this like written above, I suppose
    >> it is working on an other platform. However, I have found nothing in
    >> 6.4.9, 6.4.7 (however R3 mentions an undefined behavior if /* is
    >> between the braces or double quotes of the include directive) or 6.10
    >> and I am getting to the conclusion that this is an undefined behavior.
    >> Is my assumption right?

    >
    > If the code is exactly as you posted it, then the include directives are
    > part of a comment and should be ignored.
    >
    > My best guess is that the code is not exactly as you posted it, that
    > there's some subtle difference between the actual code and what you
    > posted (perhaps something you assumed was insignificant).


    gpp -> typo for cpp

    your guess was of course right. I did not see a comment on one of the
    include lines had a comment because line wrapping was off and it was far
    to the right side of the screen.

    thank you for your answers,
    Andreas
    Andreas Bogenberger, Feb 22, 2008
    #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. Danny Anderson
    Replies:
    5
    Views:
    495
    Victor Bazarov
    Aug 15, 2003
  2. Rolf Magnus
    Replies:
    2
    Views:
    597
    Karl Heinz Buchegger
    Nov 28, 2003
  3. Elie Nader
    Replies:
    1
    Views:
    632
  4. Eric
    Replies:
    10
    Views:
    458
  5. Eric
    Replies:
    0
    Views:
    255
Loading...

Share This Page