C++ Macros, ##, and ::

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

 



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.

Here is the original code to give you an idea of intent.

#define MT(name) { name::Type, name::Create }

struct types_t
{
  uint32_t type;
  BaseModel::CreateFn fn;
} types[] =
{
  MT(Model800),
  MT(Model900)
};
uint32_t typesLen = sizeof(types)/sizeof(types_t);

#undef MT


Thanks,

Harvey

Attachment: PGP.sig
Description: This is a digitally signed message part


[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