什么是抑制“未使用变量x”的最好方法 - 警告 [英] What is the best way to suppress "Unused variable x"-warning

查看:256
本文介绍了什么是抑制“未使用变量x”的最好方法 - 警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

禁止一个编译器(在这种情况下为gcc)的最好/最简单的方法就像未使用的变量x - 警告?

我不想给gcc任何特定的标记以删除所有这些警告,仅用于特殊情况。

解决方案

找到一篇文章 http://sourcefrog.n​​et/weblog/software/languages/C/unused.html UNUSED解释说。有趣的是,作者还破坏了未使用的变量名,所以你不能在将来无意中使用它。



摘要:

  #ifdef UNUSED 
#elif defined(__ GNUC__)
#define UNUSED(x)UNUSED_ ## x __attribute __((unused))
#elif defined(__ LCLINT__)
#define UNUSED(x)/ * @ unused @ * / x
#else
#define UNUSED(x)x
#endif

void dcc_mon_siginfo_handler(int UNUSED(whatsig))


What is the best/neatest way to suppress a compiler (in this case gcc) like "Unused variable x"-warning?

I don't want to give any certain flags to gcc to remove all these warnings, just for special cases.

解决方案

Found an article http://sourcefrog.net/weblog/software/languages/C/unused.html that explains UNUSED. Interesting that the author also mangles the unused variable name so you can't inadvertently use it in the future.

Excerpt:

#ifdef UNUSED
#elif defined(__GNUC__)
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
#elif defined(__LCLINT__)
# define UNUSED(x) /*@unused@*/ x
#else
# define UNUSED(x) x
#endif

void dcc_mon_siginfo_handler(int UNUSED(whatsig)) 

这篇关于什么是抑制“未使用变量x”的最好方法 - 警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆