Objective C MAX macro bug Objective C MAX macro bug objective-c objective-c

Objective C MAX macro bug


[array count] returns a NSUInteger -- in other words, an unsigned integer. So [array count] - 1 is not -1, it is ((NSUInteger)-1), which is 0xFFFFFFFF or something like that -- which is greater than zero.

But then when you take 0xFFFFFFFF and pass it as an argument to NSLog(@"%d"), NSLog treats it as a signed integer (because you used %d).