Re: C++ Macros, ##, and ::

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

 




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

[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