Skip to content

Instantly share code, notes, and snippets.

@nevyn
Last active August 29, 2015 14:04
Show Gist options
  • Save nevyn/fa1c5f116ca66d3bb049 to your computer and use it in GitHub Desktop.
Save nevyn/fa1c5f116ca66d3bb049 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
@interface Foo : NSObject
@property id what;
@end
@implementation Foo
- (BOOL)doingItWrong {
return _what;
}
- (BOOL)doingItRight {
return _what != nil;
}
@end
int main(int argc, char *argv[]) {
Foo *hm = [Foo new];
hm.what = (__bridge id)0xffff0000;
NSLog(@"Whaat? %d", hm.doingItWrong);
if(hm.what) {
NSLog(@"This will print since we're not truncating to bool, we're interpreting the numerical value as non-zero, which is true.");
}
if(hm.doingItWrong) {
NSLog(@"This will not print since we're truncating to bool.");
}
if(hm.doingItRight) {
NSLog(@"This will print since we're putting the result of a comparison into the bool.");
}
}
@Tricertops
Copy link

Could you run this on A7 device with 64-bit ARM? It should use correct _Bool type for BOOL and cast correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment