tags:

views:

82

answers:

1
NSArray* arr = [NSArray array];
int a = MIN([arr count], 1);      // 0   correct
int b = MIN(0 - 1, 1);            // -1  correct
int c = MIN([arr count] - 1, 1);  // 1   WRONG        

this is the definition of the MIN macro, in NSObjCRuntime.h:

#if !defined(MIN)
#define MIN(A,B)    ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
#endif
+6  A: 

NSArray’s -count method returns an NSUInteger which is unsigned, so subtracting from the count will not result in a negative value.

Ciarán Walsh
ahhhh... burned by types. :)
lawrence