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


On Mar 4, 2009, at 12:15 PM, cocoa-dev-requ...@lists.apple.com 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     gpar...@apple.com     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to