代码之家  ›  专栏  ›  技术社区  ›  Lawrence

我不理解MIN(a,b)宏中的这种奇怪行为。帮忙?

  •  1
  • Lawrence  · 技术社区  · 16 年前
    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        
    

    #if !defined(MIN)
    #define MIN(A,B)    ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
    #endif
    
    1 回复  |  直到 16 年前
        1
  •  8
  •   Ciarán Walsh    16 年前

    NSArray s -count 方法返回一个 NSUInteger