我如何隐藏“已定义但未使用”海湾合作委员会的警告? [英] How can I hide "defined but not used" warnings in GCC?

查看:157
本文介绍了我如何隐藏“已定义但未使用”海湾合作委员会的警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  CASSERT(isTrue)或CASSERT2(isTrue,prefix_) 

在使用GCC进行编译时,我收到许多警告,例如'prefix_LineNumber'使用。有没有办法隐藏编译时断言的警告?我没有找到GCC文档的运气。我想我可能会在同一个宏中自动使用全局变量,但我想不出有什么办法做到这一点。



有谁知道隐藏的方法在GCC中发出警告?

解决方案

刚刚查看此线程时搜索此问题的解决方案。我在这里发布完整的解决方案,我发现...



GCC编译器标志,控制未使用 warnings 包括:

  -Wunused-function 
-Wunused-label
-Wunused-parameter
-Wunused-value
-Wunused-variable
-Wunused(=上述全部)

每一个都有一个相应的否定形式,在关闭警告的W后插入no-例如,由-Wall打开)。因此,你应该使用

  -Wno-unused-function 

当然这适用于整个代码,而不仅仅是编译时断言。对于特定于功能的行为,请查看功能属性


I have a bunch of compile time asserts, such as:

CASSERT(isTrue) or CASSERT2(isTrue, prefix_)

When compiling with GCC I get many warnings like 'prefix_LineNumber' defined but not used. Is there a way I can hide warnings for compile time asserts? I had no luck searching the GCC documentation. I thought I might have the var automatically used globally inside the same macro but I couldn't think of any way to do it.

Does anyone know of a way to hide that warning in GCC?

解决方案

Just saw this thread while searching for solutions to this problem. I post here for completeness the solution I found...

The GCC compiler flags that control unused warnings include:

-Wunused-function
-Wunused-label
-Wunused-parameter
-Wunused-value
-Wunused-variable
-Wunused (=all of the above)

Each of these has a corresponding negative form with "no-" inserted after the W which turns off the warning (in case it was turned on by -Wall, for example). Thus, in your case you should use

-Wno-unused-function

Of course this works for the whole code, not just compile-time asserts. For function-specific behaviour, have a look at Function attributes.

这篇关于我如何隐藏“已定义但未使用”海湾合作委员会的警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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