C++ Macros, ##, and ::

Nathan Sidwell nathan@codesourcery.com
Sun Mar 30 19:28:00 GMT 2008


Daniel Lohmann wrote:
> 
> On 27.03.2008, at 21:59, Harvey Chapman wrote:
>> Why does ...
>>
>> #define MT(name) { name::Type, name::Create }
>>
>> work, and ...
>>
>> #define MT(name) { name##::Type, name##::Create }
>>
>> does not?

> AFAIK :: is a delimiter to the preprocessor (similar to ,).  Hence, the 
> first one should be portable; the latter one does not work as  the 
> result of the concatenation has to be a token.
> 
> To clarify this in the code , you could even write:
> 
>> #define MT(name) { name :: Type, name :: Create }

you are correct on all points. '::' is a token in its own right.

nathan.

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery



More information about the Gcc-help mailing list