On Sep 26, 2016, at 02:45 , Britt Durbrow 
<bdurb...@rattlesnakehillsoftworks.com> wrote:
> 
>>      void *kMyContext = &kMyContext;
>> 
>> is *guaranteed* to give you a unique address that nobody else's object may 
>> occupy?
>> 
> 
> Splitting hairs, but that’s not ***guaranteed*** - just super highly unlikely 
> to have a collision.

If you’re going to split hairs, you shouldn’t leave out half the words (“ that 
nobody else's object may occupy”). Regardless of whether you take “object” in 
the Obj-C sense or the C spec sense, no other object is going to have the same 
address. The weaker condition of a unique *pointer* can’t be guaranteed, since 
C allows any bit pattern to be cast to a pointer (as in your example).

> Also, FWIW, even declaring a single pointer variable in the global space that 
> isn’t used as an actual variable strikes me as a bit of a code smell

But if I use the above construct, then I use “kMyContext” as my context, not 
“&kMyContext”:

>       if (context != kMyContext) { [super observeValueForKeyPath: …]; return; 
> }


In that case, I really am using the value of the variable.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to