Create a gist now

Instantly share code, notes, and snippets.

Unsigned math is evil (C/Objective-C)
const NSUInteger test = 10u - 20u;
const NSInteger test2 = 10u - 20u;
const NSInteger test2_U = (NSUInteger)10 - (NSUInteger)20;
const NSUInteger test3 = 10 - 20;
const NSInteger test4 = 10 - 20;
const NSInteger test5 = 10u - 20;
64bit:
test NSUInteger 4294967286
test2 NSInteger 4294967286
test2_U NSInteger -10
test3 NSUInteger 18446744073709551606
test4 NSInteger -10
test5 NSInteger 4294967286
32bit:
test NSUInteger 4294967286
test2 NSInteger -10
test2_U NSInteger -10
test3 NSUInteger 4294967286
test4 NSInteger -10
test5 NSInteger -10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment