Aleksandrs Muravjovs
Aleksandrs Muravjovs

Reputation: 173

Conflicting parameter types in implementation of NSUInteger vs NSInteger

I have a problem with an error about conflicting parameter types in implementation of NSUInteger vs NSInteger.

I have seen a lot of similar issues and it seems that the most frequent ones happen while defining the pointer with the * character.

Integer is a primitive type and I'm not using pointers at all, so where is the problem ?

- (void) guessNumber: (NSInteger)number withRange:(NSInteger)range{


    dispatch_queue_t queue = dispatch_queue_create("com.alex.guessnumber.queue", DISPATCH_QUEUE_SERIAL);


    dispatch_async(queue, ^{

        double startTime = CFAbsoluteTimeGetCurrent();

        NSInteger randomNumber;
        NSInteger range;

        while (randomNumber != number) {
            randomNumber = arc4random_uniform(range);
        }
        NSLog(@"Student %@ guessed number %d in %f", self.name, randomNumber, CFAbsoluteTimeGetCurrent() - startTime);
    });

}

Upvotes: 0

Views: 366

Answers (1)

gnasher729
gnasher729

Reputation: 52632

arc4random_uniform returns a uint32_t with values from 0 to 2^32 - 1. You try to store this in an NSInteger, which on 32 bit systems has a range from -2^31 to +2^31 - 1. That can't work.

Upvotes: 1

Related Questions