• 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: NSNull and @""
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNull and @""


  • Subject: Re: NSNull and @""
  • From: "Michael Ash" <email@hidden>
  • Date: Sat, 11 Oct 2008 14:47:40 -0400

On Sat, Oct 11, 2008 at 1:57 PM, Seth Willits <email@hidden> wrote:
> If it's what I think you're talking about then: No, nil is used as a marker
> for the variable argument list to say "this is the end of the list." It's
> not actually inserted into the dictionary at all. Why it's required is
> really beyond me, but it's simply an Obj-C syntax thing.

It actually has to do with how C variable argument functions work.
They're called "varargs" for short, and "man stdarg" has more
information on how they work and how you can write one of your very
own.

The quickie version is that almost no information on the arguments
gets passed into the receiver. A vararg function (or method) is
allowed to do precisely three operations:

- Start reading from the vararg list.
- Read the next argument, treating it as a given type.
- Stop reading from the vararg list.

Note that nowhere in there is there anything related to how many
arguments there are, or what type they are. This means that this
information must be embedded in some other way. The printf family of
functions (including NSString's format methods) do this by embedding
the number and type of arguments in the format string, which is then
parsed to extract them from the vararg list correctly. The collection
building methods use nil to signal the end because it's the only way
they can. (Technically, they could require a count argument instead,
but I think we can all agree that this would be even *worse* in terms
of how often we'd screw it up.)

Mike
_______________________________________________

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

  • Follow-Ups:
    • Re: NSNull and @""
      • From: Seth Willits <email@hidden>
References: 
 >NSNull and @"" (From: DKJ <email@hidden>)
 >Re: NSNull and @"" (From: Seth Willits <email@hidden>)
 >Re: NSNull and @"" (From: Ian Joyner <email@hidden>)
 >Re: NSNull and @"" (From: Seth Willits <email@hidden>)
 >Re: NSNull and @"" (From: "Stelian Iancu" <email@hidden>)
 >Re: NSNull and @"" (From: Seth Willits <email@hidden>)

  • Prev by Date: Re: NSCoding protocol
  • Next by Date: Re: Can I use tool tips with images?
  • Previous by thread: Re: NSNull and @""
  • Next by thread: Re: NSNull and @""
  • Index(es):
    • Date
    • Thread