2014-03-30 159 views
1

我从来没有见过这种##模式之前和我读过的任何书籍。那么这是什么意思?我无法理解这些作品的代码,涉及##:这是什么##模式在C语言中的意思是

#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 *);      \ 
    } 

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); \ 
    }                  \ 

任何澄清表示赞赏。提前致谢!

回答

4

令牌粘贴。它的字面在它两侧的两个记号,​​粘合在一起,形成什么样子的编译器像一个新的,单一的令牌:

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

一旦添加了平常样板上面,它应编译并执行预期的事情。

+0

有关参考文献:http://www.cplusplus.com/doc/tutorial/preprocessor/ – AndyG