NSUInteger a = 100; NSUInteger b = 104; NSUInteger c = 30; NSInteger ret = a - b; if (ret > c) { //ret被隐式转换为无符号整型 NSLog(@"1"); } if (ret > (NSInteger)c) { NSLog(@"2"); } NSLog(@"ret:%ld", (long)ret); NSLog(@"ret:%lu", (unsignedlong)ret);
funcmyoverflow() { let a: UInt64=100 let b: UInt64=103 _myoverflow(a, b) } func_myoverflow(_a: UInt64, _b: UInt64) { let ret = a - b //Thread 1: Swift runtime failure: arithmetic overflow let c: Int=30 if ret > c { print("sd") } }