Xref: utzoo comp.unix.wizards:16586 comp.lang.c:19112 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!desnoyer From: desnoyer@Apple.COM (Peter Desnoyers) Newsgroups: comp.unix.wizards,comp.lang.c Subject: Re: Needed: A (Portable) way of setting up the arg stack Keywords: 1/varargs Message-ID: <32208@apple.Apple.COM> Date: 2 Jun 89 17:23:52 GMT References: <708@mitisft.Convergent.COM> Organization: Apple Computer Inc, Cupertino, CA Lines: 34 In article <708@mitisft.Convergent.COM> kemnitz@mitisft.Convergent.COM (Gregory Kemnitz) writes: > >I need to know how (or if) *NIX (System V.3) has the ability to let >a stack of arguments be set for a function before it is called. I >have several hundred pointers to functions which are called from one >place, and each function has different numbers of arguments. (I suppose >I could use the maximum number of arguments that any function has, but is >this portable??) I know how many arguments there are when I call the function, >and what those arguments are. Is there any alternative (like varargs) to >a big switch block or calling with the max number of arguments?? >-- >----------------------------------+-------------------------------------- >Greg Kemnitz | "He who does not understand baseball >kemnitz@Convergent.COM | will never understand America" > | --Tocqueville I have run into this problem in writing event-driven simulations, and have solved it two times in two different ways - (a) - use the maximum number of arguments. This won't break on any compiler I know of. However, if you want to be strictly conforming, if f is a function which you are using a pointer to, you should change f( a, b, c) f( a, b, c, ...) /* may be slightly incorrect */ so that it will be guaranteed to be able to digest the surplus arguments. (b) write a non-portable function va_call( f, n, args[]) that calls f with the N arguments in 'args'. You could write it in assembler or use inline assembler to access the stack and frame pointers. Peter Desnoyers