C++ Macros, ##, and ::

Daniel Lohmann daniel.lohmann@informatik.uni-erlangen.de
Thu Mar 27 22:39:00 GMT 2008


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?
>
> Is that first one portable? I understand the error I get for the  
> second one about name and :: not constituting a valid pre-processor  
> token, but the first one seems wrong to me. Is :: used in a macro a  
> special case? Or is it an operator? Just looking for some insight to  
> help me remember this.

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 }


(Well, just a guess -- I am *never* sure when it comes to the  
preprocessor....)


Daniel



More information about the Gcc-help mailing list