Last active
December 27, 2015 06:39
-
-
Save woolsweater/7283371 to your computer and use it in GitHub Desktop.
Lowest sizeof(signed char) bits of an object pointer determine truth? No.
This file contains 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
#if !__has_feature(objc_arc) | |
#define __unsafe_unretained | |
#define __bridge | |
#endif | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
int true_bits = 0; | |
int true_object_bits = 0; | |
int ptr_bits = 8 * sizeof(uintptr_t); | |
uintptr_t val = 1; | |
for( int bit = 0; bit < ptr_bits; bit++ ){ | |
if( val ){ | |
true_bits++; | |
} | |
__unsafe_unretained id obj = (__bridge id)(void *)val; | |
if( obj ){ | |
true_object_bits++; | |
} | |
val <<= 1LL; | |
} | |
// Both true | |
NSLog(@"%d %d", true_bits == ptr_bits, true_object_bits == ptr_bits); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment