Domanda

I never saw this ## pattern before and in any books I read. So what does this ## mean? I cannot understand these pieces of code involving ##:

#define DECLARE_STRUCT_MRC_CLASS(sfx, obj_type)         \
  struct mrc_class ## sfx {                             \
    const char *name;                                   \
    list_t subclasses;                                  \
    list_t instances;                                   \
    size_t size;                                        \
    bool initialized;                                   \
    void (*create)(obj_type *);                         \
    void (*destroy)(obj_type *);                        \
  }

and

DECLARE_STRUCT_MRC_CLASS(, struct mrc_obj);

#define MRC_CLASS_DECLARE(pfx, obj_type)                                \
  obj_type;                                                             \
  DECLARE_STRUCT_MRC_CLASS(_ ## pfx, obj_type);                         \
                                                                        \
  extern struct mrc_class_ ##pfx mrc_class_ ## pfx;                     \
  static inline obj_type *                                              \
  pfx ## _create(MPI_Comm comm)                                         \
  {                                                                     \
    return (obj_type *)                                                 \
      __mrc_obj_create(comm, (struct mrc_class *) &mrc_class_ ## pfx);  \
  }                                                                     \

Any clarification is appreciated. Thanks in advance!

È stato utile?

Soluzione

Token pasting. It literally glues together the two tokens on either side of it, to form what looks to the compiler like a new, single token:

pri ## ntf("Hello, world!\n");

Once you add the usual boilerplate to the above, it should compile and do the expected thing.

Altri suggerimenti

It is used to concatenate tokens. Hers is a detailed explaination on it: http://gcc.gnu.org/onlinedocs/cpp/Concatenation.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top