Skip to content

Instantly share code, notes, and snippets.

@woolsweater
Last active December 27, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woolsweater/7283371 to your computer and use it in GitHub Desktop.
Save woolsweater/7283371 to your computer and use it in GitHub Desktop.
Lowest sizeof(signed char) bits of an object pointer determine truth? No.
#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