-1 > 8? comparing two integers, negativeOne and eight diff than (negativeOne + 1) and (eight + 1)

StackOverflow https://stackoverflow.com/questions/16647947

  •  30-05-2022
  •  | 
  •  

문제

Here's the code:

    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;            
    }

I've checked the test values, and activeCard is -1, and allCardList has 10 members.

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

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

Any ideas?

도움이 되었습니까?

해결책

I don't code in that language but my bet is that allCardList.count returns an unsigned quantity and -2, in an attempt to push it below zero, will return you a very large unsigned number.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top