• 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: Initializing object pointers to nil
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Initializing object pointers to nil


  • Subject: Re: Initializing object pointers to nil
  • From: Gregory Weston <email@hidden>
  • Date: Thu, 17 Apr 2003 10:34:42 -0700

Jeffrey Mattox <email@hidden> wrote:

>I know that [nil release] is allowed (although I can't find
>documentation), but am I guaranteed that an object pointer will be
>nil if it hasn't been explicitly set? That is, must I declare
>variables this way:
>
> NSArray *myArray = nil;

You don't have to, but it's a good idea.

>In general, what are the ramifications of initializing variables
>where they are declared as opposed to in-line, in the code itself?

I don't know if it's still the case with modern compilers, but it used to be that initialization was faster than declare+assign. Whether that's still true or not, I'm of the opinion that setting a known sane value at the point of declaration improves readability (just as a side effect of the compaction) and reliability by ensuring that the variable has no excuse to ever be referenced in an unknown state.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: protecting time-limited demos
  • Next by Date: Fwd: FYI: [OT] Apple Design Awards
  • Previous by thread: Re: Initializing object pointers to nil
  • Next by thread: selectText field in case of Return key
  • Index(es):
    • Date
    • Thread