• 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: !foo vs foo == nil
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: !foo vs foo == nil


  • Subject: Re: !foo vs foo == nil
  • From: Sam Mo <email@hidden>
  • Date: Thu, 21 Aug 2008 08:05:42 -0400

On Aug 21, 2008, at 7:57 AM, Sam Mo wrote:

On Aug 21, 2008, at 4:47 AM, Thomas Engelmeier wrote:

Am 21.08.2008 um 05:03 schrieb Michael Ash:

There was a common perception that NULL is not really the same as nil. But
seems like in the end it really is (void*)0.

They differ in type, not in value.

"NULL" is (void *) 0.
"nil" is (id) 0.
"Nil" is (Class) 0.

This is true conceptually but not as far as their actual definition. NULL can be either 0 or (void *)0.

Let's be a little bit more precise, I'll try to paraphrase correctly from my memory:


a.)
(int) NULL is NOT required or guaranteed 0x0 by the standard. This is why one should never use
if( anPtr == (void *) 0 );
instead of
if( anPtr == NULL );
On modern machines, it usually is.

But Stroustrup says NULL is defined as 0 (zero) in C++.

	<http://www.research.att.com/~bs/bs_faq2.html#null>

With my C++ background, I normally write:

if (thePtr) {
  // do things
}
else {
  // error handling
}

Btw, I recall reading something in the PPC days that the expected case should put first so the compiler can optimize better (branch prediction?).

apparently this is also discussed in C-FAQ:

	<http://c-faq.com/null/ptrtest.html>


_______________________________________________

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: 
 >!foo vs foo == nil (From: Torsten Curdt <email@hidden>)
 >Re: !foo vs foo == nil (From: Filip van der Meeren <email@hidden>)
 >Re: !foo vs foo == nil (From: Torsten Curdt <email@hidden>)
 >Re: !foo vs foo == nil (From: "John C. Randolph" <email@hidden>)
 >Re: !foo vs foo == nil (From: "Michael Ash" <email@hidden>)
 >Re: !foo vs foo == nil (From: Thomas Engelmeier <email@hidden>)
 >Re: !foo vs foo == nil (From: Sam Mo <email@hidden>)

  • Prev by Date: Re: !foo vs foo == nil
  • Next by Date: Re: !foo vs foo == nil
  • Previous by thread: Re: !foo vs foo == nil
  • Next by thread: Re: !foo vs foo == nil
  • Index(es):
    • Date
    • Thread