Needed: A (Portable) way of setting up the arg stack

Peter Desnoyers desnoyer at Apple.COM
Sat Jun 3 03:23:52 AEST 1989


In article <708 at mitisft.Convergent.COM> kemnitz at 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 at 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



More information about the Comp.unix.wizards mailing list