#, ## preprocessor operator weirdness with g++

  • Thread starter Guenter Dannoritzer
  • Start date
G

Guenter Dannoritzer

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
 
J

Justin Spahr-Summers

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';
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top