2013-05-20 58 views
-1

這裏存在8個差分的代碼:-1> 8?比較兩個整數,negativeOne比(negativeOne + 1)和(8 + 1)

while((fingerYLast - fingerAt.y) > fingerMoveThresh) 
    { 
     if((activeCard) < (allCardList.count - 2)) 
     { 
      [self sayOut:@"TRUE"]; 
      activeCard = activeCard + 1; 
     } 
     else 
     { 
      //WTF???? 
      [self sayOut:[NSString stringWithFormat:@"FALSE %i %i", 
          activeCard, (allCardList.count - 2)]]; 
     } 
     fingerYLast -= fingerMoveThresh;    
    } 

我檢查測試值,並activeCard是-1,allCardList有10名成員。

activeCard = -1; 
(activeCard) < (allCardList.count - 2) //evaluates as false 

(activeCard+1) < (allCardList.count - 1) //evaluates as true 

任何想法?

+2

'activeCard'的類型是什麼? – Femaref

+0

對不起,activeCard是int,allCardList是一個NSMutableArray。 – redux

回答

3

我不用那種語言編碼,但我敢打賭,所有CardList.count都返回一個無符號數量和-2,試圖將它推到零以下,會返回一個非常大的無符號數。