* Using the ## preprocessing operator fails
@ 2011-08-26 14:54 Ike Starnes
2011-08-26 17:08 ` Jonathan Wakely
0 siblings, 1 reply; 3+ messages in thread
From: Ike Starnes @ 2011-08-26 14:54 UTC (permalink / raw)
To: gcc-help
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?
--
View this message in context: http://old.nabble.com/Using-the----preprocessing-operator-fails-tp32342472p32342472.html
Sent from the gcc - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Using the ## preprocessing operator fails
2011-08-26 14:54 Using the ## preprocessing operator fails Ike Starnes
@ 2011-08-26 17:08 ` Jonathan Wakely
2011-08-26 18:04 ` Ike Starnes
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2011-08-26 17:08 UTC (permalink / raw)
To: Ike Starnes; +Cc: gcc-help
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Using the ## preprocessing operator fails
2011-08-26 17:08 ` Jonathan Wakely
@ 2011-08-26 18:04 ` Ike Starnes
0 siblings, 0 replies; 3+ messages in thread
From: Ike Starnes @ 2011-08-26 18:04 UTC (permalink / raw)
To: gcc-help
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-08-26 18:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-26 14:54 Using the ## preprocessing operator fails Ike Starnes
2011-08-26 17:08 ` Jonathan Wakely
2011-08-26 18:04 ` Ike Starnes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).