• 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: Method not seeing array as array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Method not seeing array as array


  • Subject: RE: Method not seeing array as array
  • From: Jeff Laing <email@hidden>
  • Date: Fri, 4 Feb 2005 14:41:13 +1100

> > The problem with "if (!self)" is that you're assuming that
> nil is equal to zero.

(snip)

No, thats not the problem.

> /usr/include/objc/objc.h. lines 51-57:
> #ifndef nil
> #define nil 0        /* id of Nil instance */
> #endif
>
> As for documentation, according to the objective-C language overview
>
> "The keyword nil is defined as a null object, an id with a value of 0.

Ok, there's a bug for you then. The above header does *not* define nil as
"an id with ..." - instead, its "an integer with ..."

If you implement to the word of the spec, you'd have

#ifndef nil
#define nil ((id)0)
#endif

which strict type-checking compilers may well barf on since ! is not a
defined operation for pointer types.  Or is it?

I've seen C++ compilers that definitely reject this sort of thing, but some
skate along on the lazy assumptions that says that the literal 0 is
type-compatible with any pointer, and they define !x as ( x != 0 ).

Sure, Objective-C is not C++, but then again, someone might pick up your
code and try to ram it through Objective-C++ which may well have to adhere
to stricter language specs.

Having said all that, I prefer the (!ptr) syntax but I recognise that its a
lot easier to overlook in a page full of text, and *try* to use (ptr == nil)
wherever I can.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Method not seeing array as array
  • Next by Date: HFS+ File Question
  • Previous by thread: Re: Method not seeing array as array
  • Next by thread: RE: Method not seeing array as array
  • Index(es):
    • Date
    • Thread