• 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: Checking for NULL (was "Re: Can't get setDelegate to work...")
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Checking for NULL (was "Re: Can't get setDelegate to work...")


  • Subject: Re: Checking for NULL (was "Re: Can't get setDelegate to work...")
  • From: Greg Parker <email@hidden>
  • Date: Wed, 4 Mar 2009 16:03:45 -0800


On Mar 4, 2009, at 2:40 PM, Stuart Malin wrote:


On Mar 4, 2009, at 12:15 PM, email@hidden wrote:

In any case, and perhaps based purely on habit, I find it difficult to
even write:


	NSStatusItem statusItem = [[[NSStatusBar systemStatusBar]
		statusItemWithLength:NSVariableStatusItemLength] retain];

...in favor of:

	NSStatusBar *systemBar = [NSStatusBar systemStatusBar];
	if (systemBar != NULL)
	{

AFAIU(nderstand):

While nil and NULL may operate interchangeably (in most cases?), semantically, they are not the same thing.

In your code fragment above, I believe most Cocoa programmers would expect to see:

	if (systemBar != nil) ....

NULL is used more to indicate a null value c pointer.

At one time I was under the impression they were defined differently:
nil being of type id, and NULL being a void*
But in trying to research this, I run across much conflicting info and suspect perhaps this has either changed over time, and/or depends on whether the use is in/with C++ or not. Perhaps some of the experts on this list can provide some clarity....

Technically, nil and NULL are identical. As of Mac OS X 10.5, nil and NULL are both defined as __DARWIN_NULL, which is handled specially by the compiler for typechecking and a few C vs C++ corner cases.


Stylistically, you may prefer to distinguish nil and NULL as a C vs Objective-C hint to the reader.

(Before 10.5, nil was defined as 0, which would have caused trouble for 64-bit: sizeof(nil) != sizeof(id). There's also a Nil, which was originally intended to be the nil class but is now mostly unused.)


-- Greg Parker email@hidden Runtime Wrangler


_______________________________________________

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: 
 >Re: Checking for NULL (was "Re: Can't get setDelegate to work...") (From: Stuart Malin <email@hidden>)

  • Prev by Date: Re: Newbie: Learning path for my GTD app...
  • Next by Date: Re: Text scrolling with Finder-like label editing. Will a raw field editor (NSTextView) do this, or should I use an NSTextField or NSTextFieldCell? [COROLLARY]
  • Previous by thread: Re: Checking for NULL (was "Re: Can't get setDelegate to work...")
  • Next by thread: A question about Apple Policy
  • Index(es):
    • Date
    • Thread