macros again

Discussion in 'C Programming' started by borophyll@gmail.com, Aug 24, 2007.

  1. Guest

    Sorry for my perverse interest in the C preprocessor, but I have a
    question about a subtle matter. Yesterday, Eric brought up a point
    about the following case, indicating how preprocessing input should be
    treated as tokens rather than text. He gave this example

    #define A *
    #define B /

    B* Not a comment A/

    While GCC produces the preprocessor output

    / * Not a comment */

    This generates 6 tokens. Would it be perfectly valid if I wrote a
    preprocessor implementation that would produces 7 tokens as such

    / * Not a comment * /

    since technically A and / are separate tokens before being
    preprocessed. While GCC seems to combine these two tokens into one, I
    guess technically there is nothing wrong with this, since */ is an
    invalid token at this stage anyway.

    regards, B
     
    , Aug 24, 2007
    #1
    1. Advertising

  2. Army1987 Guest

    On Fri, 24 Aug 2007 04:07:19 +0000, borophyll wrote:

    > Sorry for my perverse interest in the C preprocessor, but I have a
    > question about a subtle matter. Yesterday, Eric brought up a point
    > about the following case, indicating how preprocessing input should be
    > treated as tokens rather than text. He gave this example
    >
    > #define A *
    > #define B /
    >
    > B* Not a comment A/
    >
    > While GCC produces the preprocessor output
    >
    > / * Not a comment */
    >
    > This generates 6 tokens. Would it be perfectly valid if I wrote a
    > preprocessor implementation that would produces 7 tokens as such
    >
    > / * Not a comment * /
    >
    > since technically A and / are separate tokens before being
    > preprocessed. While GCC seems to combine these two tokens into one, I
    > guess technically there is nothing wrong with this, since */ is an
    > invalid token at this stage anyway.


    I think so, but it would be less confusing if it added whitespace
    to show the token boundary.
    Compare with
    #define PLUS +
    i+PLUS

    it must expand in i+ +, which is a valid sequence because I could
    write i+PLUS 5.
    If the output of the preprocessor was text, it couldn't be i++
    because that's two tokens, i ++, they should be three, i + +.
    --
    Army1987 (Replace "NOSPAM" with "email")
    No-one ever won a game by resigning. -- S. Tartakower
     
    Army1987, Aug 24, 2007
    #2
    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,432
    Stephen J. Bevan
    Nov 7, 2003
  2. Replies:
    1
    Views:
    449
    Marco Antoniotti
    Oct 7, 2003
  3. Replies:
    5
    Views:
    497
  4. Michael T. Babcock

    Re: Explanation of macros; Haskell macros

    Michael T. Babcock, Nov 3, 2003, in forum: Python
    Replies:
    0
    Views:
    517
    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:
    496
    S.Tobias
    Jul 24, 2004
Loading...

Share This Page