Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!think!snorkelwacker!paperboy!meissner From: meissner@osf.org (Michael Meissner) Newsgroups: comp.lang.c Subject: Re: Grabbing "n" arguments in a function Message-ID: Date: 3 May 90 15:24:39 GMT References: <744@tmiuv0.uucp> <559@dplace.UUCP> <297@ndla.UUCP> <347@brontolo.sublink.ORG> Sender: news@OSF.ORG Organization: Open Software Foundation Lines: 52 In-reply-to: peter@brontolo.sublink.ORG's message of 28 Apr 90 21:55:37 GMT In article <347@brontolo.sublink.ORG> peter@brontolo.sublink.ORG (Network administrator) writes: | In article <297@ndla.UUCP>, platt@ndla.UUCP (Daniel E. Platt) writes: | ] In article <559@dplace.UUCP>, djl@dplace.UUCP (Dave Lampe) writes: | ] > rick@tmiuv0.uucp writes: | ] > | ] > >What's the most portable way for a function to receive an arbitrary list of | ] > >arguments? The function must receive "n" arguments, all of which are char. | ] > >pointers: | ] > | ] > > char *weirdfunc(char *arg1, char *arg2, ... char *argn) { | ] > | ] ...In your case | ] you'ld continue popping the things from the stack until you got a NULL. | | Dan's method to get arguments from the function's stack is very usefull, | and is worth ok on every OS and C compiler I have tried, exept for the | DEC's RISC one. | | Does anybody out there know how to do the same variable argument call | (WITHOUT "varargs", please! [it doesn't work, too!!!!!]) under MIPS | RISC workstation (or DEC's one) ????????? | Thank you By the way, it probably won't work for any other implementation that passes arguments in registers (including most RISC processors, like the 88k). For machines that pass things in registers, the compiler has to store any registers normally used for passing arguments for varargs type arguments. For MIPS-based processors, this means storing $4-$7 in the appropriate locations on the stack (which the caller must allocate). MIPS machines have another fly in the ointment, in that if the first argument to a function is floating point, it is passed in a floating point register, and not an integer register, which totally messes up any varargs function with a floating point number as the first argument. For the 88k, it is more complicated, since structures are passed on the stack (unlike MIPS), so you can't arbitrarily store the registers in their 'home' location, so you save r2-r7 in a special 8 word area, and use a state variable within the varargs routine to index through the special 8 word area, or the normal stack argument area. Finally, there are machines like the Data General MV, whose stack grows backwards to most other machines in the universe. There are good reasons why the varargs/stdarg layer is necessary, and if your problem can't use varargs/stdarg, you would be well advised to take some different tack. -- Michael Meissner email: meissner@osf.org phone: 617-621-8861 Open Software Foundation, 11 Cambridge Center, Cambridge, MA Catproof is an oxymoron, Childproof is nearly so