Re: Objective-C variadic methods vs. NSArray et al.
Re: Objective-C variadic methods vs. NSArray et al.
- Subject: Re: Objective-C variadic methods vs. NSArray et al.
- From: Scott Thompson <email@hidden>
- Date: Fri, 21 Nov 2008 17:53:27 -0600
On Nov 21, 2008, at 5:52 PM, Clark Cox wrote:
On Fri, Nov 21, 2008 at 3:40 PM, Scott Thompson <email@hidden> wrote:
Technical QA 1405 concerns the creation of Objective-C methods that
take
variable number of arguments... so called variadic methods.
Happily the
mechanisms just use the standard C mechanisms (va_start and friends).
That being the case, why is it that methods like arrayWithObjects:
require
you to nil terminate the list of arguments? Is it simply
tradition, or some
kind of optimization?
Without the nil, how would the method know when to stop fetching
arguments with va_arg? This is true in C too, you have to have some
way that tells you how many parameters are being passed and what types
they are, and there are generally only two ways to do this:
1) Have the information encoded in the first parameter (like a printf
format string)
2) Have some sentinel value marking the end of the list (like the nil
passed to arrayWithObjects:)
Ah... I see.
_______________________________________________
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