Comparison of unsigned expression >=0 is always true
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 ex开发者_开发知识库pression then>
Thanks!
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.
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.
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.
You must have written a statement which can never be executed
I am having this because i do something like this..
if (textField.text.length < 0) //wrong logic
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 .
精彩评论