Last active
August 29, 2015 14:04
-
-
Save nevyn/fa1c5f116ca66d3bb049 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you run this on A7 device with 64-bit ARM? It should use correct
_Bool
type forBOOL
and cast correctly.