无符号表达式 >=0 的比较始终为真
我收到警告 Comparison of unsigned expression >=0 is always true
在这一行中:return status != nil && status.length >= 0 && status.length <= 140;
所以我不确定这听起来是否愚蠢,但我应该删除该表达式然后>
谢谢!
I get the warning Comparison of unsigned expression >=0 is always true
In this line:return status != nil && status.length >= 0 && status.length <= 140;
So I am not sure if this sounds stupid or not but should I just delete that expression then>
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只删除这部分检查 — status.length >= 0。实际上,这部分检查将由编译器优化并自动删除,因为它没有意义。从代码中删除它将帮助您摆脱此警告。
Remove just this part of a check — status.length >= 0. Actually this part of a check will be optimized by compiler and removed automatically as it not make sense. Removing it form a code will help you to get rid from this warning.
是的 - 由于 length 返回一个无符号整数,因此它将始终“大于或等于 0”。您可以删除条件的 status.length >= 0 部分。
Yes - since length returns an unsigned integer, it will always be 'greater than or equal to 0'. You can delete the status.length >= 0 portion of the conditional.
如果您想确保没有零长度字符串,那么您应该使用条件
status.length > 0 。
否则,您可以删除该条件,正如其他人提到的那样。
If you want to make sure that you don't have a zero-length string, then you should use the condition
status.length > 0
.Otherwise, you can remove that condition, as others have mentioned.
你一定写了一条永远无法执行的语句
我之所以这样,是因为我做了这样的事情。
textField 的文本长度永远不能小于 0 。它必须至少为0。
每当编译器看到这种永远不可能(执行)的逻辑错误时。它会生成这种警告。如果有人遇到此错误,请正确检查您的逻辑。
You must have written a statement which can never be executed
I am having this because i do something like this..
textField's text length can never be less than 0 . It must be at least 0.
Whenever complier see such kind of logical error which can never be possible (executed) . It generates this kind of Warning. If anyone is having this error so properly check your logic .