使用define定义命名空间

使用define定义命名空间

#include 


#define MSG(sym) msg_  ## sym //提供命名空间

struct MSG(BoardConfiguration){
    int num;
    const char *name;
};

struct MSG(HostConfiguration){
    int num;
    const char *name;
};

int main()
{
    MSG(BoardConfiguration) conf;
    conf.num = 10;
    conf.name = "Tom";

    MSG(HostConfiguration) conf_h;
    conf_h.num = 10;
    conf_h.name = "Tom";

    printf("Board: num:%d, Name:%s.\n", conf.num, conf.name);
    printf("HOST: num:%d, Name:%s.\n", conf_h.num, conf_h.name);

    return 0;
}

你可能感兴趣的:(C语言,C++)