[gameprogrammer] GCC macros question

  • From: Alan Wolfe <alan.wolfe@xxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Wed, 11 Apr 2012 12:34:55 -0700

Hey Guys,

I have a macro that works in MSVC, but I just can't seem to get it working
in gcc.

The macro looks like this:

#define DECLAREWEBSERVICECALL_TWOARGS(CallName,Arg1,Arg2) \
public: \
void CallName(Arg1,Arg2,WebServiceCallback pCallback, void *pUserData,
const char *szLoadingText = NULL); \
void Cancel##CallName()
{CRayTracer::GetSingleton().GetPlatform().CancelHTTPRequestsOfType(CPlatformBase::k##CallName);}
\
static void StaticCB_Cancel##CallName(void *)
{WebService::GetSingleton().Cancel##CallName();} \
private: \
DEFINE_SINGLETONCALLBACK_THREEARGS(WebService,On##CallName##HTTPDone,void
*,ERequestFinishCode,const char *)

And an example of it's use is like this:

DECLAREWEBSERVICECALL_TWOARGS(Login, const char *szUsername, const char
*szPassword)

gcc complains about the 4th line of the macro:

static void StaticCB_Cancel##CallName(void *)
{WebService::GetSingleton().Cancel##CallName();} \

With the error:

RTCode/WebService.h:68:1: error: pasting "{" and "WebService" does not give
a valid preprocessing token

So i tried adding a ## onto the end of CallName in each place so the line
looked like this:

static void StaticCB_Cancel##CallName##(void *)
{WebService::GetSingleton().Cancel##CallName##();} \

But then i get these errors:

RTCode/WebService.h:68:1: error: pasting "StaticCB_CancelLogin" and "("
does not give a valid preprocessing token
RTCode/WebService.h:68:1: error: pasting "CancelLogin" and "(" does not
give a valid preprocessing token

I tried a couple other things that were also fruitless.

Anyone know the right way to do this in gcc?

Other related posts: