• 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: Bill Bumgarner <email@hidden>
  • Date: Sat, 11 Oct 2008 21:38:14 -0700

On Oct 11, 2008, at 3:26 PM, Seth Willits wrote:
Note that nowhere in there is there anything related to how many
arguments there are, or what type they are.

Ahh. I guess I mis-remembered varargs. I thought they did have a count. I'm


You can tell how often I've had to use it ;-)

Nope --you remembered correctly. Almost.

How varargs are interpreted is entirely up to whatever is interpreting the varargs. Here are two methods from the kit:

NSString.h:+ (id)stringWithFormat:(NSString *)format, ...;

NSArray.h:+ (id)arrayWithObjects:(id)firstObj, ... NS_REQUIRES_NIL_TERMINATION;

And one method that I'm making up:

Foo.h:+ (id)fooWithCount: (unsigned) i bars: (Bar *) bar1, ...;

All three are perfectly valid varargs style methods and all three have completely different means of interpreting the varargs. The key to varargs is that that there has to be something somewhere -- be it documentation or format string -- that tells the vararg taking method how to decade the unknown set of arguments properly.

And in all cases, there has to be some magic somewhere that indicates when to stop trying to pull more args off the stack. Hence the fragility of varargs. And, thank goodness for that NS_REQUIRES_NIL_TERMINATION macro (which expands to a compiler attribute). Prior to that, programs would compile without warning and then crash at runtime because someone would do:

[NSArray arrayWithObjects: one, two, three];

No warning. Often work in debug mode sometimes. *boom* most of the time.

Varargs really aren't much fun.  Powerful, but a pain.

b.bum

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: 
 >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>)
 >Re: NSNull and @"" (From: "Michael Ash" <email@hidden>)
 >Re: NSNull and @"" (From: Seth Willits <email@hidden>)

  • Prev by Date: Re: NSTableView and drag and drop
  • Next by Date: Re: NSTableView and drag and drop
  • Previous by thread: Re: NSNull and @""
  • Next by thread: Re: NSNull and @""
  • Index(es):
    • Date
    • Thread