Re: Stupid objective-c question
Re: Stupid objective-c question
- Subject: Re: Stupid objective-c question
- From: Quincey Morris <email@hidden>
- Date: Mon, 26 Sep 2016 10:28:36 -0700
- Feedback-id: 167118m:167118agrif8a:167118sS5zSm_QeE:SMTPCORP
On Sep 26, 2016, at 02:45 , Britt Durbrow <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden