Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!uunet!hsi!stpstn!lerman From: lerman@stpstn.UUCP (Ken Lerman) Newsgroups: comp.sys.next Subject: Re: methods with arbitrary # of args? How? Keywords: varargs Message-ID: <5687@stpstn.UUCP> Date: 16 Oct 90 11:10:52 GMT References: <3860@network.ucsd.edu> Reply-To: lerman@stpstn.UUCP (Ken Lerman) Organization: The Stepstone Corporation, Sandy Hook, CT 06482 Lines: 53 In article <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)? [...] >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 This is done in (more or less) the same manner as in plain old C (K&R): #include + with: (unsigned) nArgs, ... { va_list vp; va_start(vp); while (nArgs-- > 0) { int arg = va_arg(vp,int); } va_end(vp); return self; } or, in ANSI C: #include + with: (unsigned) nArgs, ... { va_list vp; va_start(vp,nArgs); while (nArgs-- > 0) { int arg = va_arg(vp,int); } va_end(vp); return self; } depending on whether your Objective-C compiler is targeted for ANSI or K&R. Your interface file should include the line: + with: (unsigned) nArgs, ...; Note that the next Stepstone release of Objective-C will use the macro VA_START(v,n) which will work for either of the above environments. Also, there is no need to include either of the above files if you include Object.h (because it will include the proper file). In this matter, I speak for myself, not for Stepstone. Ken