Search code examples
c++macrosg++xlc

Macro stopped to compile on Linux


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. 

Solution

  • 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.