Re: NSNull and @""
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