#, ## preprocessor operator weirdness with g++

Discussion in 'C++' started by Guenter Dannoritzer, Nov 24, 2007.

  1. Hi,

    I have a piece of code that got developed using Microsoft .NET 2003 and
    I try to compile it with g++/gcc 4.1.2.

    There is a problem with the string concatenation operator for the
    preprocessor. The following is a piece of code:

    #define GET_DOUBLE_PARM_ARRAY(X,N) {X =
    ParmInput->GetDoubleParmArray(#X##"\0",X,N);}

    which causes the following error message:

    error: pasting ""A_Coeffs"" and ""\0"" does not give a valid
    preprocessing token

    when called like this:

    GET_DOUBLE_PARM_ARRAY(A_Coeffs, ar_size);

    I had other cases where the concatenation operator was used in
    connection with a cout stream and I just replaced it by <<. But here I
    have no idea how to solve it.

    Can anybody give me some help how to resolve that?

    Why does g++ not like this?

    Thanks for your help.

    Cheers,

    Guenter
     
    Guenter Dannoritzer, Nov 24, 2007
    #1
    1. Advertising

  2. On Nov 23, 6:31 pm, Guenter Dannoritzer <>
    wrote:
    > Hi,
    >
    > I have a piece of code that got developed using Microsoft .NET 2003 and
    > I try to compile it with g++/gcc 4.1.2.
    >
    > There is a problem with the string concatenation operator for the
    > preprocessor. The following is a piece of code:
    >
    > #define GET_DOUBLE_PARM_ARRAY(X,N) {X =
    > ParmInput->GetDoubleParmArray(#X##"\0",X,N);}
    >
    > which causes the following error message:
    >
    > error: pasting ""A_Coeffs"" and ""\0"" does not give a valid
    > preprocessing token
    >
    > when called like this:
    >
    > GET_DOUBLE_PARM_ARRAY(A_Coeffs, ar_size);


    The preprocessor concatenation operator is used for *token*
    concatenation, not *string* concatenation. To concatenate two strings,
    one only has to place them next to each other. For instance,

    const char *s = "foo" "bar";
    std::cout << s << '\n';
     
    Justin Spahr-Summers, Nov 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. Cronus
    Replies:
    1
    Views:
    714
    Paul Mensonides
    Jul 15, 2004
  2. steve
    Replies:
    4
    Views:
    555
    Brian van den Broek
    Mar 13, 2005
  3. mrstephengross
    Replies:
    8
    Views:
    689
    Jack Klein
    Oct 12, 2005
  4. zahy[dot]bnaya[At]gmail[dot]com

    Using the % operator with preprocessor constants

    zahy[dot]bnaya[At]gmail[dot]com, Mar 8, 2006, in forum: C++
    Replies:
    2
    Views:
    317
    Ben Pope
    Mar 8, 2006
  5. Bernhard Singer

    tr operator weirdness

    Bernhard Singer, Dec 14, 2006, in forum: Perl Misc
    Replies:
    6
    Views:
    121
    Paul Lalli
    Dec 14, 2006
Loading...

Share This Page