Path: utzoo!attcan!uunet!wuarchive!sdd.hp.com!ucsd!ucbvax!agate!shelby!SUMEX-AIM.STANFORD.EDU!lane From: lane@SUMEX-AIM.STANFORD.EDU (Christopher Lane) Newsgroups: comp.sys.next Subject: re: methods with arbitrary # of args? How? Message-ID: Date: 15 Oct 90 18:38:55 GMT References: <3860@network.ucsd.edu> Sender: Christopher Lane Organization: Internet-USENET Gateway at Stanford University Lines: 35 In <3860@network.ucsd.edu>, pbiron@weber.ucsd.edu 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)? #import /* actually imported by Object.h file anyway */ #import @interface MyObject : Object { } - myMethod:arg1, ...; @end @implementation MyObject - myMethod:arg1, ... { va_list ap; va_start(ap, arg1); /* f = va_arg(ap, type); */ va_end(ap); return self; } @end To be able to figure out the number of arguments actually given at runtime, you have to either include that information in the value of 'arg1', pass and test for an explicit NULL at the end of the list of arguments or pass off the whole lot to something else that handles multiple arguments (e.g vsprintf). - Christopher -------