LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
123
返回列表 发新帖
楼主: Illidan

[C] 一个函数声明中带了两个##,什么意思?

[复制链接]
发表于 2005-5-20 12:19:44 | 显示全部楼层
我以前这样写也能用

#define   debug(ARG...)   printf("DEBUG in "__FUNCTION__": "ARG)

不知道和上面的写法有啥区别。
回复 支持 反对

使用道具 举报

发表于 2005-5-20 15:29:25 | 显示全部楼层
Post by doubleelec
我以前这样写也能用

#define   debug(ARG...)   printf("DEBUG in "__FUNCTION__": "ARG)

不知道和上面的写法有啥区别。

没有什么区别,预处理会自动把字符串拼接在一起。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-24 12:22:51 | 显示全部楼层
Post by kj501
不过话说回来,楼主没有给出完整的宏定义,很有可能我们都说错了。

真是不好意思,前几天没时间来读各位的高见。我已经明白了大概。
如果要看那个宏及所调用的函数的完整信息,那么看下边:

  1. #define cpLog(priority__, fmt__, args__...) \
  2. do {if (priority__ <= cpLogGetPriority()) \
  3. cpLog_impl_ (priority__, __FILE__, __LINE__, fmt__ , ##args__);} \
  4. while (0)
复制代码

  1. /*declaration*/
  2. extern void cpLog_impl_ (int pri, const char* file, int line, const char* fmt, ...);
复制代码


  1. /*implementation*/
  2. void cpLog_impl_(int pri, const char* file, int line, const char* fmt, ...)
  3. {
  4.     va_list ap;

  5.     if (pri <= CpLogPriority::getPriority())
  6.     {
  7.           Lock lock(cpLogMutex);
  8.         va_start(ap, fmt);
  9.         vCpLog(pri, file, line, fmt, ap);
  10.         va_end(ap);
  11.     }
  12. /*Illidan note: va_start and va_end are macros, while vCplog is a function.*/
  13. }
复制代码


Mr. kj501说得很全面  :cool:
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表