[comp.lang.objective-c] methods with arbitrary # of args? How?

pbiron@weber.ucsd.edu (Paul Biron) (10/16/90)

Is it possible to define an obj-c method which takes an
arbitrary number of arguments (ala normal C functions
which use varargs.h)?

If so, how?  If not, does anybody have an "elegent" way
to simulate this kind of behavior?

Any advice would be appreciated.

Paul Biron      pbiron@ucsd.edu        (619) 534-5758
Central University Library, Mail Code C-075-R
Social Sciences DataBase Project
University of California, San Diego, La Jolla, Ca. 92093

pbiron@weber.ucsd.edu (Paul Biron) (10/17/90)

In <3860@network.ucsd.edu>, pbiron@weber.ucsd.edu (Paul Biron) writes:

	>Is it possible to define an obj-c method which takes an
	>arbitrary number of arguments (ala normal C functions
	>which use varargs.h)?

The net comes through again, thanx to those who responded!!!

The "answer" is, (from NeXT manuals, Chap 3, p 12):

	Methods that take a varaible number of arguments declare them
	just as a function would.

	- makeGroup:group,... ;

That's it!  No mention of how to call them though!!!!  However,
in Chap 22, p 31 (the Spec sheet for Object), there's an example
call of Objects error: method which is a vararg method (sorry,
I forgot to write down the call, but it went something like this):

	- error:(STR)str,... ;

	[self error:"index %d is greater than max %d\n", index, max] ;

IOW, the _method_ only has 1 argument, but that 1 argument is made
up of comma separated "arguments".

Note that the same kinds of restrictions that apply to the use
of varargs.h, apply here.

I have also been told there is an example of this in Issue 9 of
the _NeXT User's Journal_, in the Buzz Hints section.

Thanx again to those who pointed me in the right direction!

Paul Biron      pbiron@ucsd.edu        (619) 534-5758
Central University Library, Mail Code C-075-R
Social Sciences DataBase Project
University of California, San Diego, La Jolla, Ca. 92093