• 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: Fri, 23 Sep 2016 02:04:33 -0700
  • Feedback-id: 167118m:167118agrif8a:167118sS5zSm_QeE:SMTPCORP

On Sep 23, 2016, at 01:36 , Alastair Houghton <email@hidden> wrote:
>
> Note that you can use *any* type for your variable; in some ways, it might make sense to use a non-pointer type, just to make clear that it’s the address that matters, e.g.
>
>  static const int kMyContext = 0xabadf00d;
>
> Otherwise some smart-ass might go and delete the “&” operators from your code, and that makes it vulnerable to problems.

As previously mentioned, the safest way to do this is:

> static void* kMyContext = &kMyContext;


That makes the “&” optional (at comparison time), and it should even avoid the coalescing problem if it’s declared const.

_______________________________________________

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


  • Follow-Ups:
    • Re: Stupid objective-c question
      • From: Sandor Szatmari <email@hidden>
    • Re: Stupid objective-c question
      • From: Alastair Houghton <email@hidden>
    • Re: Stupid objective-c question
      • From: Jonathan Mitchell <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: Alastair Houghton <email@hidden>)

  • Prev by Date: Re: Stupid objective-c question
  • Next by Date: Re: Stupid objective-c question
  • Previous by thread: Re: Stupid objective-c question
  • Next by thread: Re: Stupid objective-c question
  • Index(es):
    • Date
    • Thread