On 26 August 2011 15:54, Ike Starnes wrote: > > The following code builds fine in Microsoft C, but fails with gcc / g++: > > > #include <iostream> > > using namespace std; > > typedef struct _THREADDATA > { > int nConvTiles; // the number of swap buffers in a tiled bitmap > used for caching the disk tiles (default 1) > } > THREADDATA, *pTHREADDATA; > > #define DECLARETHREADDATA() pTHREADDATA pThreadData = NULL; > #define GETTHREADDATA() pThreadData > #define THREADVALUE(v) GETTHREADDATA()->##v > > static int GetTilesInfo() > { > DECLARETHREADDATA(); > int nConvTiles; > nConvTiles = THREADVALUE(nConvTiles); > return nConvTiles; > } > > int main() > { > cout << "Hello world!" << endl; > cout << GetTilesInfo(); > return 0; > } > > > With gcc, the error is: > d:\temp\GNU\HelloWorld\main.cpp:19:1: error: pasting "->" and "nConvTiles" > does not give a valid preprocessing token > > Does anyone know the correct fix? Just remove the ## from your macro. ## is for pasting two tokens together into one, but in your macro there's only one token. Just get rid of it and it will work: #define THREADVALUE(v) GETTHREADDATA()->v