C语言中##

在看Redis中第一次见##,##被称为连接符(concatenator),用来将两个Token连接为一个Token

 

 

#include <stdio.h>

void quit_command(){
    printf("I am quit command\n");
}
void help_command(){
    printf("I am help command\n");
}
struct command
{
    char * name;
    void (*function) (void);
};
#define COMMAND(NAME) {#NAME,NAME##_command}
#define PRINT(NAME) printf("token"#NAME"=%d\n", token##NAME)
int main(){
    int token9=9;
    PRINT(9);
    struct command commands[] = {
        COMMAND(quit),
        COMMAND(help),
    };
    commands[0].function();
}

 

posted @ 2021-06-06 21:29  尘归风  阅读(1180)  评论(0编辑  收藏  举报