On macros

Discussion in 'C Programming' started by Nickolai Leschov, Feb 28, 2008.

  1. 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
     
    Nickolai Leschov, Feb 28, 2008
    #1
    1. Advertising

  2. Nickolai Leschov

    Eric Sosman Guest

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

    --
     
    Eric Sosman, Feb 28, 2008
    #2
    1. Advertising

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

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
     
    Richard Heathfield, Feb 28, 2008
    #3
  4. Nickolai Leschov

    Eric Sosman Guest

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


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

    --
     
    Eric Sosman, Feb 28, 2008
    #4
  5. Eric Sosman wrote:
    >
    > ... 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.
     
    Nickolai Leschov, Feb 28, 2008
    #5
  6. Richard Heathfield wrote:
    > 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.
     
    Nickolai Leschov, Feb 28, 2008
    #6
    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. Replies:
    80
    Views:
    2,491
    Stephen J. Bevan
    Nov 7, 2003
  2. Replies:
    1
    Views:
    476
    Marco Antoniotti
    Oct 7, 2003
  3. Replies:
    5
    Views:
    511
  4. Michael T. Babcock

    Re: Explanation of macros; Haskell macros

    Michael T. Babcock, Nov 3, 2003, in forum: Python
    Replies:
    0
    Views:
    534
    Michael T. Babcock
    Nov 3, 2003
  5. Andrew Arro

    macros-loop? calling macros X times?

    Andrew Arro, Jul 23, 2004, in forum: C Programming
    Replies:
    2
    Views:
    513
    S.Tobias
    Jul 24, 2004
Loading...

Share This Page