尹绵绵

 

宏定义:带参数的宏名和为空的宏体

在wxwidgets中遇到这样的一个宏

1 /* Macro to cut down on compiler warnings. */
2 #if 1 /* there should be no more any compilers needing the "#else" version */
3 #define WXUNUSED(identifier) /* identifier */
4 #else /* stupid, broken compiler */
5 #define WXUNUSED(identifier) identifier
6 #endif

还有这样的一处应用

void DoLogString(const wxChar *szString, time_t WXUNUSED(t))

看的有点懵,网上找了几篇宏定义的规则,举的例子都是带有宏体的,自己试了几个例子才明白这个宏的作用。

这个宏的作用就是把括号内的参数给屏蔽掉,因为他的宏体为空,也就相当于用空字符来替换他的参数。

在上面的这个函数体内,是看不到参数t的,也就相当于下面的定义

void DoLogString(const wxChar *szString, time_t)

很不起眼的小技巧,却让我着实烦躁了一会儿...

posted on 2012-03-19 22:13  花无形  阅读(1408)  评论(2编辑  收藏  举报

导航