清理“未使用的参数”编译警告? [英] Clean up "unused parameter" compiler warnings?

查看:97
本文介绍了清理“未使用的参数”编译警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有很多功能,例如:

int funct1(int arg1,int arg2,int arg3);

int funct2(int arg1,int arg2,int arg3);

int funct3(int arg1,int arg2,int arg3);


通过指针调用在一个表格中,与

相同的参数,无论特定的

函数如何。


在某些函数中,一个或者更多的

参数未使用。这可能导致

编译器警告这样的参数

未被使用。


我可以通过以下方式使编译器静音添加一个声明

喜欢:

arg2 = arg2;
每个受影响的函数
,但这似乎有点像
笨拙。


是否有已批准的处理这个

的方法适用于所有或(大多数)C编译器

和操作系统?


谢谢你你的帮助。


问候,

Charles Sullivan

解决方案

< blockquote> Charles Sullivan写道:


在某些函数中,一个或多个

参数未使用。这可能导致

编译器警告这样的参数

未被使用。


我可以通过以下方式使编译器静音添加一个声明

喜欢:

arg2 = arg2;
每个受影响的函数
,但这似乎有点像$ b $笨拙。



然后你会收到一个警告,即arg2的值永远不会使用
。理想情况下,关闭所有这些愚蠢的警告。但是在

编译器中,这是不可能的,我这样做:


NOT_USED(arg2);


然后在一个特定于该编译器的头文件中,

定义一些适用于该编译器的东西,而不是
产生警告。这里有编译器的一些选项

我使用:


#define NOT_USED(x)((void)(x))


#define NOT_USED(x)(*(volatile typeof(x)*)&(x)=(x);)


Old Wolfaécrit:


Charles Sullivan写道:


>>在某些对于这些功能,一个或多个
参数未使用。这可能导致
编译器警告这样的参数
未被使用。

我可以通过添加声明来使编译器静音
如:
arg2 = arg2;
每个受影响的功能,但这似乎有点笨拙。




然后你会收到一个警告,即arg2的值永远不会使用
。理想情况下,关闭所有这些愚蠢的警告。但是在

编译器中,这是不可能的,我这样做:


NOT_USED(arg2);


然后在一个特定于该编译器的头文件中,

定义一些适用于该编译器的东西,而不是
产生警告。这里有编译器的一些选项

我使用:


#define NOT_USED(x)((void)(x))


#define NOT_USED(x)(*(volatile typeof(x)*)&(x)=(x);)



扩展是有用的!


这是一个很棒的应用类型。 (还支持

由我知道的某个Windows编译器):-)




" ;查尔斯沙利文 < cw ****** @ triad.rr.com在留言中写道

news:pa ********************** ***** @ triad.rr.com ...


>

我有很多功能,例如:

int funct1(int arg1,int arg2,int arg3);

int funct2(int arg1,int arg2,int arg3);

int funct3(int arg1,int arg2,int arg3);


通过表中的指针调用,

相同的参数,无论特定的

函数。


在某些函数中,一个或多个

参数未使用。这可能导致

编译器警告这样的参数

未被使用。


我可以通过以下方式使编译器静音添加一个声明

喜欢:

arg2 = arg2;
每个受影响的函数
,但这似乎有点像
笨拙。


是否有已批准的处理这个

的方法适用于所有或(大多数)C编译器

和操作系统?


谢谢你你的帮助。


问候,

Charles Sullivan



*有些*编译器会识别出来非标准

/ * ARGSUSED * /

评论函数定义正上方:


/ * ARGSUSED * /

int funct1(int arg1,int arg2,int arg3){

/ *此函数的正文* /

}


再说一次,这不是标准的,但你总是可以试试它/ b $ b并查看你的编译器是否关闭。

-

Fred L. Kleinschmidt

波音助理技术研究员

技术架构师,软件重用项目



I have a number of functions, e.g.:
int funct1( int arg1, int arg2, int arg3 );
int funct2( int arg1, int arg2, int arg3 );
int funct3( int arg1, int arg2, int arg3 );

that are called via pointers in a table, with the
same parameters regardless of the particular
function.

In some of the functions, one or more of the
parameters are unused. This can result in the
compiler warning that such and such a parameter
is unused.

I can silence the compiler by adding a statement
like:
arg2 = arg2;
to each affected function, but that seems sort of
clumsy.

Is there an "approved" way of dealing with this
which will work on all or (most all) C compilers
and OSes?

Thanks for your help.

Regards,
Charles Sullivan

解决方案

Charles Sullivan wrote:

In some of the functions, one or more of the
parameters are unused. This can result in the
compiler warning that such and such a parameter
is unused.

I can silence the compiler by adding a statement
like:
arg2 = arg2;
to each affected function, but that seems sort of
clumsy.

Then you get a warning that the value of arg2 is never
used. Ideally, turn off all these stupid warnings. But on
compilers where that isn''t possible, I do this:

NOT_USED(arg2);

and then in a piece of header file specific to that compiler,
define something that will work for that compiler and not
produce a warning. Here''s some options from compilers
I use:

#define NOT_USED(x) ( (void)(x) )

#define NOT_USED(x) ( *(volatile typeof(x) *)&(x) = (x); )


Old Wolf a écrit :

Charles Sullivan wrote:

>>In some of the functions, one or more of the
parameters are unused. This can result in the
compiler warning that such and such a parameter
is unused.

I can silence the compiler by adding a statement
like:
arg2 = arg2;
to each affected function, but that seems sort of
clumsy.



Then you get a warning that the value of arg2 is never
used. Ideally, turn off all these stupid warnings. But on
compilers where that isn''t possible, I do this:

NOT_USED(arg2);

and then in a piece of header file specific to that compiler,
define something that will work for that compiler and not
produce a warning. Here''s some options from compilers
I use:

#define NOT_USED(x) ( (void)(x) )

#define NOT_USED(x) ( *(volatile typeof(x) *)&(x) = (x); )

Extensions ARE useful!

This is a wonderful application of typeof. (Also supported
by a certain windows compiler I know) :-)



"Charles Sullivan" <cw******@triad.rr.comwrote in message
news:pa***************************@triad.rr.com...

>
I have a number of functions, e.g.:
int funct1( int arg1, int arg2, int arg3 );
int funct2( int arg1, int arg2, int arg3 );
int funct3( int arg1, int arg2, int arg3 );

that are called via pointers in a table, with the
same parameters regardless of the particular
function.

In some of the functions, one or more of the
parameters are unused. This can result in the
compiler warning that such and such a parameter
is unused.

I can silence the compiler by adding a statement
like:
arg2 = arg2;
to each affected function, but that seems sort of
clumsy.

Is there an "approved" way of dealing with this
which will work on all or (most all) C compilers
and OSes?

Thanks for your help.

Regards,
Charles Sullivan

*Some* compilers will recognize the non-standard
/* ARGSUSED */
comment immediately above the function definition:

/* ARGSUSED */
int funct1( int arg1, int arg2, int arg3 ) {
/* Body of the function here */
}

Again, this is NOT standard, but you could always try it
and see if your compiler shuts up.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project


这篇关于清理“未使用的参数”编译警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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