0

I have a library with several macros, it compiles fine on AIX, but now i need to compile the same code and it seems the macros stopped to work. I keep receiving the message:

error: pasting "::" and "EVENT_DATA" does not give a valid preprocessing token.

Is there a way to make the c++ preprocessor on linux acts like on aix. I'm using g++ on linux and xlc_r on AIX.

Here is one of the macros.

#define E_TRA_INMOD(MName, Comp) \
   static const ES_TracMg::ES_TracComps ES_TracComp = \
                                    ES_TracMg::##Comp; \
   static char* ES_Mod_Namp = MName; \
   static unsigned long ES_SerMas = \
               ES_TracMg::m_MServ[ES_TracMg##Comp];

I call it like E_TRA_INMOD("Error", EVENT_DATA);
The error is:

error: pasting "::" and "EVENT_DATA" does not give a valid preprocessing token. 
Martin York
  • 257,169
  • 86
  • 333
  • 562
Lefsler
  • 1,738
  • 6
  • 26
  • 46

2 Answers2

2

I think you don't want to use ## here:

#define E_TRA_INMOD(MName, Comp) \
   static const ES_TracMg::ES_TracComps ES_TracComp = \
                                    ES_TracMg::##Comp; \

It should be

#define E_TRA_INMOD(MName, Comp) \
   static const ES_TracMg::ES_TracComps ES_TracComp = \
                                    ES_TracMg::Comp; \

You don't have two tokens to glue together into a single token, you just have whatever Comp expands to.

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
0

What are you trying to do in the macro? It looks like the first token paste is redundant:

#define E_TRA_INMOD(MName,Comp) \
   static const ES_TracMg::ES_TracComps ES_TracComp = \
                                    ES_TracMg::Comp; \
   static char* ES_Mod_Namp = MName; \
   static unsigned long ES_SerMas = \
               ES_TracMg::m_MServ[ES_TracMg##Comp];
ecatmur
  • 152,476
  • 27
  • 293
  • 366