Re: Using the ## preprocessing operator fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks!


Jonathan Wakely-4 wrote:
> 
> 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
> 
> 

-- 
View this message in context: http://old.nabble.com/Using-the----preprocessing-operator-fails-tp32342472p32343873.html
Sent from the gcc - Help mailing list archive at Nabble.com.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux