public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ Macros, ##, and ::
@ 2008-03-27 21:00 Harvey Chapman
  2008-03-27 22:39 ` Daniel Lohmann
  2008-03-31 23:38 ` Philipp Thomas
  0 siblings, 2 replies; 4+ messages in thread
From: Harvey Chapman @ 2008-03-27 21:00 UTC (permalink / raw)
  To: MSX to GCC

[-- Attachment #1: Type: text/plain, Size: 737 bytes --]

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 #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-03-31 23:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-27 21:00 C++ Macros, ##, and :: Harvey Chapman
2008-03-27 22:39 ` Daniel Lohmann
2008-03-30 19:28   ` Nathan Sidwell
2008-03-31 23:38 ` Philipp Thomas

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).