Lefsler
Lefsler

Reputation: 1768

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. 

Upvotes: 0

Views: 111

Answers (2)

ecatmur
ecatmur

Reputation: 157424

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

Upvotes: 0

Jonathan Wakely
Jonathan Wakely

Reputation: 171393

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.

Upvotes: 2

Related Questions