参考如下博客,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 },
}
本文展示了一段使用C语言预处理宏的示例代码,包括警告信息的输出宏、命令定义宏及链接多个参数的宏。通过这些宏定义,实现了代码的简洁性和灵活性。
1114

被折叠的 条评论
为什么被折叠?



