警告 - 将签名值与未指定值进行比较 [英] warning - comparing a signed value to an unsinged value

查看:55
本文介绍了警告 - 将签名值与未指定值进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您认为处理编译器警告的最佳方法是什么?

将无符号值与有符号值进行比较?施展沉默吗?

完全禁用该警告?或者只是忍受它?


一方面,警告*可能*很有用。大部分时间我都会在

的情况下得知它,我知道比较是安全的,但不难想象

这不会永远是案子。这使得禁用它是不可取的。

Casting是一个可行的解决方案,但我担心代码中的更改后来可能会引入由于强制转换而未检测到的错误。我认为我们都讨厌没有清洁的东西。编译(如果只是因为你预期有一堆
警告会让你更难以发现你没想到的那些

)。


你有什么看法?


谢谢。


-Kevin

-

我的电子邮件地址有效,但会定期更改。

要联系我,请使用最近发布的地址。

What do you think is the best way to handle a compiler warning about
comparing an unsigned value to a signed value? Cast to silence it?
Disable that warning altogether? Or just live with it?

On one hand, the warning *could* be useful. Most of the time I get it in
cases where I know the comparison is safe, but it''s not hard to imagine
that this won''t always be the case. This makes disabling it undesirable.
Casting is a workable solution, but I worry that changes in the code
later could introduce errors that go undetected due to the cast. And I
think we all hate not having a "clean" compile (if only because having a
bunch of warnings that you expected makes it more difficult to spot the
ones you didn''t expect).

What is your opinion?

Thanks.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

推荐答案

Kevin Goodsell写道:
Kevin Goodsell wrote:
您认为处理编译器警告的最佳方法是什么?
将无符号值与已签名值进行比较值?施展以保持沉默?
完全禁用该警告?或者只是忍受它?
What do you think is the best way to handle a compiler warning about
comparing an unsigned value to a signed value? Cast to silence it?
Disable that warning altogether? Or just live with it?




您可以随时修复代码,这样您就不会将签名与

进行比较。



You could always fix the code so that you aren''t comparing a signed to
an unsigned.




" Kevin Goodsell" <我们********************* @ neverbox.com>在留言中写道

新闻:mI ***************** @ newsread3.news.pas.earthl ink.net ...

"Kevin Goodsell" <us*********************@neverbox.com> wrote in message
news:mI*****************@newsread3.news.pas.earthl ink.net...
您认为处理编译器警告的最佳方法是什么?
将无符号值与有符号值进行比较?
What do you think is the best way to handle a compiler warning about
comparing an unsigned value to a signed value?



[snip]


如果你正在使用gcc那么;

gcc -W -Wall foo.c


-

=====================================

Alex Vinokur

mailto:al **** @ connect.to
http://mathforum.org/library/view/10978.html
news://news.gmane.org/gmane.comp.lang.c++.perfometer

====== ===============================


[snip]

If you are using gcc then ;
gcc -W -Wall foo.c

--
=====================================
Alex Vinokur
mailto:al****@connect.to
http://mathforum.org/library/view/10978.html
news://news.gmane.org/gmane.comp.lang.c++.perfometer
=====================================


Kevin Goodsell写道:
Kevin Goodsell wrote:

您认为处理编译器警告的最佳方法是什么? br />将无符号值与有符号值进行比较?施展以保持沉默?
完全禁用该警告?或者只是忍受它?

What do you think is the best way to handle a compiler warning about
comparing an unsigned value to a signed value? Cast to silence it?
Disable that warning altogether? Or just live with it?




IME,这通常发生在你有一个函数检查一个范围内的int

值时,通常通过sizeof派生(size_t,这是

unsigned)。在这种情况下,我的建议是修复你的功能,以便

你使用size_t作为范围和索引。


/ david


-

安德烈,一个简单的农民,只有一件事在他的脑海中悄悄地沿着东墙悄悄地上涨:''安德烈,蠕动......安德烈,蠕动......安德烈,蠕动。''

- 未知



IME, this usually occurs when you have a function which checks an int
value against some range, typically derived via sizeof (size_t, which is
unsigned). My suggestion, in this case, is to fix your functions so that
you use size_t for ranges and indices.

/david

--
Andre, a simple peasant, had only one thing on his mind as he crept
along the East wall: ''Andre, creep... Andre, creep... Andre, creep.''
-- unknown


这篇关于警告 - 将签名值与未指定值进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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