(GCC) How can I hide "defined but not used" warnings in GCC?

GCC警告抑制技巧
本文介绍如何在GCC中隐藏已定义但未使用的警告。通过使用特定的编译器标志,如-Wno-unused-function,可以有效地控制这些警告的显示。此外,还探讨了如何针对特定函数定制警告行为。

2014-02-14 wcdj


May happy ending of love belong to every developer.

From: http://play.golang.org/p/xl1P6jYtIZ


Question:

How can I hide "defined but not used" warnings in GCC?


Answers:

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 atFunction attributes.


stackoverflow:

http://stackoverflow.com/questions/386220/how-can-i-hide-defined-but-not-used-warnings-in-gcc



record.c: In function 'record_thread_func': record.c:2727:15: error: invalid storage class for function 'rec_chn_deinit' static STATUS rec_chn_deinit() ^~~~~~~~~~~~~~ record.c:2864:15: error: invalid storage class for function 'rec_chn_init' static STATUS rec_chn_init() ^~~~~~~~~~~~ record.c:3197:1: error: expected declaration or statement at end of input } ^ At top level: record.c:3189:6: error: 'record_init_status' defined but not used [-Werror=unused-function] BOOL record_init_status() ^~~~~~~~~~~~~~~~~~ record.c:3183:6: error: 'record_clear_event' defined but not used [-Werror=unused-function] void record_clear_event() ^~~~~~~~~~~~~~~~~~ record.c:3151:5: error: 'record_intercom_reload' defined but not used [-Werror=unused-function] S32 record_intercom_reload(void) ^~~~~~~~~~~~~~~~~~~~~~ record.c:3146:5: error: 'record_audio_reload' defined but not used [-Werror=unused-function] S32 record_audio_reload(void) ^~~~~~~~~~~~~~~~~~~ record.c:3141:5: error: 'record_adv_reload' defined but not used [-Werror=unused-function] S32 record_adv_reload(void) ^~~~~~~~~~~~~~~~~ record.c:3097:5: error: 'record_stop' defined but not used [-Werror=unused-function] S32 record_stop(void) ^~~~~~~~~~~ record.c:3074:5: error: 'record_start' defined but not used [-Werror=unused-function] S32 record_start(void) ^~~~~~~~~~~~ record.c:2898:5: error: 'record_init' defined but not used [-Werror=unused-function] S32 record_init(void) ^~~~~~~~~~~ record.c:2717:8: error: 'rec_get_snapshot' defined but not used [-Werror=unused-function] STATUS rec_get_snapshot(U32 timestamp, REC_PHOTO_INFO_S *data) ^~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors 什么报错?没有识别到?
最新发布
10-30
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值