如何处理未使用的变量
2015-11-08 01:56
501 查看
有一些函数传入了没有任何作用的变量,但是,这些变量在以后可能会用上(可扩展性)。
而编译器一般会发出警告,提示该变量没有被使用。如何处理这种case呢?
业界有一行统一的代码来解决这个问题。
其中的:
就是用来处理这种情况。
UNUSED宏定义如下:
明白了吧?
而编译器一般会发出警告,提示该变量没有被使用。如何处理这种case呢?
业界有一行统一的代码来解决这个问题。
handler_t stat_cache_handle_fdevent(server *srv, void *_fce, int revent) { size_t i; stat_cache *sc = srv->stat_cache; size_t events; UNUSED(_fce); /* */ if ((revent & FDEVENT_IN) && sc->fam) { events = FAMPending(sc->fam); for (i = 0; i < events; i++) { FAMEvent fe; fam_dir_entry *fam_dir; splay_tree *node; int ndx, j; FAMNextEvent(sc->fam, &fe); /* handle event */ switch(fe.code) { case FAMChanged: case FAMDeleted: case FAMMoved: /* if the filename is a directory remove the entry */ fam_dir = fe.userdata; fam_dir->version++; /* file/dir is still here */ if (fe.code == FAMChanged) break; /* we have 2 versions, follow and no-follow-symlink */ for (j = 0; j < 2; j++) { buffer_copy_string(sc->hash_key, fe.filename); buffer_append_long(sc->hash_key, j); ndx = hashme(sc->hash_key); sc->dirs = splaytree_splay(sc->dirs, ndx); node = sc->dirs; if (node && (node->key == ndx)) { int osize = splaytree_size(sc->dirs); fam_dir_entry_free(node->data); sc->dirs = splaytree_delete(sc->dirs, ndx); assert(osize - 1 == splaytree_size(sc->dirs)); } } break; default: break; } } } if (revent & FDEVENT_HUP) { /* fam closed the connection */ srv->stat_cache->fam_fcce_ndx = -1; fdevent_event_del(srv->ev, &(sc->fam_fcce_ndx), FAMCONNECTION_GETFD(sc->fam)); fdevent_unregister(srv->ev, FAMCONNECTION_GETFD(sc->fam)); FAMClose(sc->fam); free(sc->fam); sc->fam = NULL; } return HANDLER_GO_ON; }
其中的:
UNUSED(_fce);
就是用来处理这种情况。
UNUSED宏定义如下:
#define UNUSED(x) ( (void)(x) )
明白了吧?
相关文章推荐
- kmemleak_object的优化patch
- Linux源代码解析之——传输控制块诞生
- 切换Fragment,改变Toolbar menu的显示样式
- Linux逻辑地址与物理地址的key point
- 大端字节(Big endian)与小端字节(Little endian)
- X86 32位的基本寄存器
- .NET 2.0 CookieContainer bug
- DMA为什么比轮询、中断方式性能要卓越很多?
- 源代码VS业务的悟道——知行合一
- 外企巨头与互联网巨头的成功之道
- 数据库与共享内存
- Linux内核收包精髓
- 点破Redis的VM
- 图解mysql块读取代码
- 一切数据都是字节流
- 数组指针的意义
- C语言版Mysql存储块(page)格式读取工具(源代码)
- Mysql与Oracle group by的不同之处
- MariaDB 5.5.34 QPS bug手记
- Redis的Client设计