9
votes

NSNotFound is defined as NSIntegerMax, which is defined as LONG_MAX.

NSRange.location is defined as a NSUInteger.

Some Foundation methods return an NSRange whose location value is NSNotFound.

So, one often does this comparison:

if (aRange.location == NSNotFound) 

But isn't that a comparison between signed and unsigned integers that should generate a warning?

1

1 Answers

12
votes

You are comparing an unsigned (64 bit) variable with a signed constant which also fits into the range of the variable (it is not negative). So no need for a warning.

The warnings appear typically when comparing against negative constants or variables on both sides (i.e. one part is or can be negative while the other is only positive or zero).

A side note: NSNotFound is different on 32 bit vs 64 bit platforms, so don't hardcode or store that value anywhere.