0

I'm getting the following warning Comparison of unsigned expression < 0 is always false.

I'm not sure how to fix it ?

if(topWindowIndex < 0)

It's defined as...

NSUInteger topWindowIndex = [allWindows count] - 1;
4

3 回答 3

9

If [allWindows count] - 1 can never be negative, the test (and the code it controls) is unnecessary. If it can be negative, you should declare topWindowIndex as a signed type (int or NSInteger).

A better solution, IMO, is to store the count directly and use that instead:

NSUInteger numWindows = [allWindows count];
...
if (numWindows < 1) ...
于 2011-11-09T22:15:00.980 回答
2

这很危险

NSUInteger topWindowIndex = [allWindows count] - 1;

如果[allWindows count]是 0,你会得到一个非常大的数字(废话)作为 topWindowIndex。

于 2011-11-09T22:20:17.150 回答
0

上述答案的基本答案:

使用NSInteger代替NSUInteger(无符号)。

于 2014-09-29T19:59:29.207 回答