• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Stupid objective-c question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Stupid objective-c question (From: Gabriel Zachmann <email@hidden>)
 >Re: Stupid objective-c question (From: Graham Cox <email@hidden>)
 >Re: Stupid objective-c question (From: Quincey Morris <email@hidden>)
 >Re: Stupid objective-c question (From: Graham Cox <email@hidden>)
 >Re: Stupid objective-c question (From: Doug Hill <email@hidden>)
 >Re: Stupid objective-c question (From: Jens Alfke <email@hidden>)
 >Re: Stupid objective-c question (From: Gabriel Zachmann <email@hidden>)
 >Re: Stupid objective-c question (From: Quincey Morris <email@hidden>)
 >Re: Stupid objective-c question (From: Sandor Szatmari <email@hidden>)
 >Re: Stupid objective-c question (From: Uli Kusterer <email@hidden>)
 >Re: Stupid objective-c question (From: Britt Durbrow <email@hidden>)

  • Prev by Date: Re: SecStaticCodeCheckValidity fails when app is lauched from Terminal
  • Next by Date: Re: SecStaticCodeCheckValidity fails when app is lauched from Terminal
  • Previous by thread: Re: Stupid objective-c question
  • Next by thread: Re: Stupid objective-c question
  • Index(es):
    • Date
    • Thread