focus on linux, c/c++, lua

宏的##连接符

“##”把两个独立的字符串连接成一个字符串:
#include <stdio.h>
#define SORT(type) sort_##type
void sort_int(int **i);
void sort_long(long **l);
void sort_float(float **f);
void sort_char(char **c);
void main(void);
void main(void)
{
int **ip;
long **lp;
float **fp;
char **cp;

SORT(int)(ip);
SORT(long)(lp);
SORT(float)(fp);
SORT(char)(cp);

}
程序对四种数据类型排序。SORT(int)(ip);经编译预处理转换为sort_int(ip);这个宏对类型不敏感。如果在运行时才能确定调用哪个函数,可用此法。


posted on 2010-10-20 10:28 zuhd 阅读(774) 评论(0)  编辑 收藏 引用 所属分类: c/c++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理