C语言宏定义##连接符和#符的使用

来源:互联网 发布:淘宝折扣价在哪设置 编辑:程序博客网 时间:2024/06/07 10:59

参考如下博客,http://blog.csdn.net/dotphoenix/article/details/4345174

写了一个测试程序,代码和运行结果如下:


#include "stdlib.h"

#include "stdio.h"


#define WARN_IF(EXP)    do{ if (EXP)    fprintf(stderr, "Warning: " #EXP "/n"); }   while(0)


#define COMMAND(NAME) { NAME, NAME ## _command }


#define LINK_MULTIPLE(a,b,c,d) a##_##b##_##c##_##d




int main()
{
WARN_IF (divider == 0);

struct command
{
char * name;
void (*function) (void);
};

struct command commands[] = {
COMMAND(quit),
COMMAND(help),
}

printf("main end...\n");
//typedef struct _record_type LINK_MULTIPLE(name,company,position,salary);
}




//test result:
 do{ if (divider == 0) fprintf(stderr, "Warning: " "divider == 0" "/n"); } while(0);


 struct command
 {
  char * name;
  void (*function) (void);
 };


 struct command commands[] = {
  { quit, quit_command },
  { help, help_command },
 }