"does not give a valid preprocessing token"... Why?

Discussion in 'C Programming' started by Frodo Baggins, Sep 15, 2004.

  1. Hi All,

    I have a piece of code (not written by me) that is failing on compile with
    the error:
    pasting "xdr_ndmp_connect_open_request" and "," does not
    give a valid preprocessing token

    The relevant line from the header is:
    #define XDR_AND_SIZE(func) (bool_t(*)(XDR*, ...))xdr_##func##,sizeof(func)

    Any and all help greatly appreciated.
    Frodo Baggins, Sep 15, 2004
    #1
    1. Advertising

  2. Frodo Baggins

    Ben Pfaff Guest

    Frodo Baggins <> writes:

    > pasting "xdr_ndmp_connect_open_request" and "," does not
    > give a valid preprocessing token
    >
    > The relevant line from the header is:
    > #define XDR_AND_SIZE(func) (bool_t(*)(XDR*, ...))xdr_##func##,sizeof(func)


    Remove the second ##. It looks like its inclusion was a mistake.
    --
    Here's a tip: null pointers don't have to be *dull* pointers!
    Ben Pfaff, Sep 15, 2004
    #2
    1. Advertising

  3. Frodo Baggins <> scribbled the following:
    > Hi All,


    > I have a piece of code (not written by me) that is failing on compile with
    > the error:
    > pasting "xdr_ndmp_connect_open_request" and "," does not
    > give a valid preprocessing token


    > The relevant line from the header is:
    > #define XDR_AND_SIZE(func) (bool_t(*)(XDR*, ...))xdr_##func##,sizeof(func)


    > Any and all help greatly appreciated.


    C tokenising doesn't work like you think it does. The , (commma) that
    separates function parameters is a token on its own, not part of some
    greater token that comprises the entire function invocation.
    In other words, your function invocation would read tokenised like this:

    (
    bool_t
    (
    *
    )
    (
    XDR
    *
    ,
    ....
    )
    )
    xdr_func
    ,
    sizeof
    (
    func
    )

    The ## preprocessing operator concatenates two pieces of text into one
    single token. This makes the invocation read like this:

    (
    bool_t
    (
    *
    )
    (
    XDR
    *
    ,
    ....
    )
    )
    xdr_func,
    sizeof
    (
    func
    )

    See the difference? You end up with a token saying "xdr_func," (note
    the comma) which is not a legal identifier, operator or punctuator.

    To fix this, simply replace the second ## with a space.

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "Make money fast! Don't feed it!"
    - Anon
    Joona I Palaste, Sep 15, 2004
    #3
  4. On Wed, 15 Sep 2004 18:14:31 +0000, Joona I Palaste wrote:

    > See the difference? You end up with a token saying "xdr_func," (note
    > the comma) which is not a legal identifier, operator or punctuator.
    >
    > To fix this, simply replace the second ## with a space.


    That was it exactly. Thank you both Joona and Ben. :)
    Frodo Baggins, Sep 16, 2004
    #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. =?Utf-8?B?VGltOjouLg==?=

    Why, why, why???

    =?Utf-8?B?VGltOjouLg==?=, Jan 27, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    553
    Juan T. Llibre
    Jan 27, 2005
  2. Horace Nunley

    why why why does function not work

    Horace Nunley, Sep 27, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    450
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Sep 27, 2006
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    863
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,763
    Smokey Grindel
    Dec 2, 2006
  5. girishk.k4
    Replies:
    0
    Views:
    981
    girishk.k4
    Mar 23, 2013
Loading...

Share This Page