C 下面的宏是什么意思?

C 下面的宏是什么意思?,c,macros,C,Macros,下面的代码定义了一个宏,但我不知道它是如何工作的。我需要一个解释 typedef struct { char *cmdname; /* String containing the name of the command */ void (*func)(int); /* Pointer to the action function */ char *help; /* Help string for the comma

下面的代码定义了一个宏,但我不知道它是如何工作的。我需要一个解释

    typedef struct 
    {
    char *cmdname;       /* String containing the name of the command    */
    void (*func)(int);   /* Pointer to the action function */
    char *help;          /* Help string for the command */
    } parse_table;

    #define ADD_CMD(name,f,helptxt) \
    const parse_table f##E __attribute__ ((section(".parsetable." name)))    = { \
    .cmdname = name,  \
    .func    = f, \
    .help    = helptxt };

如果将该宏用作

ADD_CMD("abc1", func_abc1, "abc1 help text")
ADD_CMD("abc2", func_abc2, "abc2 help text")
ADD_CMD("abc3", func_abc3, "abc3 help text")
它将由预处理器扩展到

const parse_table func_abc1E __attribute__ ((section(".parsetable." "abc1"))) =
{ .cmdname = "abc1", .func = func_abc1, .help = "abc1 help text" };
const parse_table func_abc2E __attribute__ ((section(".parsetable." "abc2"))) =
{ .cmdname = "abc2", .func = func_abc2, .help = "abc2 help text" };
const parse_table func_abc3E __attribute__ ((section(".parsetable." "abc3"))) =
{ .cmdname = "abc3", .func = func_abc3, .help = "abc3 help text" };
因此,它允许您通过编写
ADD\u CMD
行来定义和分配许多类似的结构

ADD_CMD()
仅替换其参数,并对
f
执行以下操作:

“##”预处理运算符执行标记粘贴。当一个宏 展开后,每个“##”运算符两侧的两个标记为 组合成一个令牌,然后替换“##”和两个 宏扩展中的原始标记


你试过阅读文档吗?看起来是VS.我的教授给了我这些代码。我不理解这些“attribute((section(“.parsetable.”name)))”部分,我宁愿将
const char*
作为结构元素。如果您仍然不理解文档,请在阅读文档后询问您的教授。
\uuu attribute\uu((第节…
是一个特定于gcc的扩展-有关更多详细信息,请参阅gcc手册。其余部分只是简单的C99结构初始化。