如何消除gcc编译警告 warning: "unused parameter xxxx"

han012 2010-05-18 04:20:02
客户要求使用gcc -Wall 选项编译代码,并且解决所有编译警告.

但对于函数的保留参数,目前确实在函数体中没有使用, 但又不能从函数声明中删除保留参数。请问如何处理保留参数,才能消除由于使用gcc编译选项-Wunused-parameter而导致的 warning: "unused parameter xxxx"警告。谢谢!
...全文
6492 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
x666777 2011-08-09
  • 打赏
  • 举报
回复
看看,是用的一个宏吗
lasting820676 2011-01-25
  • 打赏
  • 举报
回复
厉害 很笨笨的天才方法,能否通过修改编译参数解决呀
Stanley_L_zhao 2010-10-29
  • 打赏
  • 举报
回复
useful.
魔都布衣 2010-09-15
  • 打赏
  • 举报
回复
很笨笨的天才方法,能否通过修改编译参数解决呀
魔都布衣 2010-09-15
  • 打赏
  • 举报
回复
正好需要这样的信息,编译的时候一堆这样的告警,很不爽,尝试一下看看是否解决问题
han012 2010-05-19
  • 打赏
  • 举报
回复
非常感谢,确实解决了我的问题
超龄编码人 2010-05-18
  • 打赏
  • 举报
回复
真是一个奇才
mymtom 2010-05-18
  • 打赏
  • 举报
回复
建议用这个。

#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))

来自http://sourcefrog.net/weblog/software/languages/C/unused.html
steptodream 2010-05-18
  • 打赏
  • 举报
回复
来自网上
第一种方法
#define UNUSED(x) (void)x
void SomeFunction(int param1, int param2)
{
UNUSED(param2);
// do stuff with param1
}

在UNUSED(param2)语句不产生任何目标代码,消除对未使用的变量的警告,并明确文件,不要使用变量的代码。

第二种方法
warning: unused parameter 'mcb'
举例:
int ifnMenuQuit(MCB_T *mcb)
{
return QUIT;
}
说明:因为函数参数中的mcb,在该函数中没有被使用,所以产生warning
修改:对没使用的参数使用 para=para;
int ifnMenuQuit(MCB_T *mcb)
{
mcb=mcb; <----------添加该行
return QUIT;
}
全志R16平台编译linux系统V1.0.txt 2017/4/11 13:36 (编译请使用编译android的lichee的选项编译生成的.config文件,不然直接编译会报错!!!!) rootroot@cm-System-Product-Name:/home/wwt/linux_r16$ tar zxvf lichee_parrotv1.1_20161202.tar.gz rootroot@cm-System-Product-Name:/home/wwt/linux_r16$ cd lichee/ rootroot@cm-System-Product-Name:/home/wwt/linux_r16/lichee$ ./build.sh config Welcome to mkscript setup progress All available chips: 0. sun8iw5p1 Choice: 0 All available platforms: 0. android 1. dragonboard 2. linux 3. tina Choice: 2 All available kernel: 0. linux-3.4 Choice: 0 All available boards: 0. bell-one 1. evb 2. evb-20 3. evb-30 4. evb-rtl8723bs 5. sc3813r Choice: 3 rootroot@cm-System-Product-Name:/home/wwt/linux_r16/lichee$ ./build.sh 错误1: KCONFIG_AUTOCONFIG=/home/wwt/linux_r16/lichee/out/sun8iw5p1/linux/common/buildroot/build/buildroot-config/auto.conf KCONFIG_AUTOHEADER=/home/wwt/linux_r16/lichee/out/sun8iw5p1/linux/common/buildroot/build/buildroot-config/autoconf.h KCONFIG_TRISTATE=/home/wwt/linux_r16/lichee/out/sun8iw5p1/linux/common/buildroot/build/buildroot-config/tristate.config BUILDROOT_CONFIG=/home/wwt/linux_r16/lichee/out/sun8iw5p1/linux/common/buildroot/.config /home/wwt/linux_r16/lichee/out/sun8iw5p1/linux/common/buildroot/build/buildroot-config/conf --silentoldconfig Config.in # # make dependencies written to .auto.deps # ATTENTION buildroot devels! # See top of this file before playing with this auto-preprequisites! # make[1]:正在离开目录 `/home/wwt/linux_r16/lichee/buildroot' You must install 'makeinfo' on your build machine makeinfo is usually part of the texinfo package in your distribution make: *** [dependencies] 错误 1 make:离开目录“/home/wwt/linux_r16/lichee/buildroot” ERROR: build buildroot Failed rootroot@cm-System-Product-Name:/home/wwt/linux_r16/lichee$ d/buildroot-config/conf.o /home/wwt/linux_r16/lichee/out/sun8iw5p1/linux/common/buildroot/build/buildroot-config/zconf.tab.o -o /home/wwt/linux_r16/lichee/out/sun8iw5p1/linux/common/buil

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧