Arrays of functions - calling them with different number of args.

ihor.j.kinal ijk at cbnewsh.ATT.COM
Fri Mar 2 01:08:34 AEST 1990


I've set up an array of 50 functions, to be called with one standard
argument, and my function call looks like this [which particular
function to be called is determined by the action_ind.

			action_tbl [ action_ind ] ( one_arg )
				
	where the one_arg is a pointer to a particular type.
	
Now, I want to add some functions that will have two arguments.

The question is, how do I express the call to that function
both simply and portably?

Obviously, I could provide a list of arguments for each function
in my table, and I could test if an arg two is present, then I call

			action_tbl [ action_ind ] ( one_arg, two_arg )

and otherwise, call the old way.  This seems incredibly clumsy.

Alternately, I could call EVERY function with two arguments,
with the second being null for the actual one-arg functions.

Note that I don't want to go back to the source and add a dummy argument
to all the old functions.

Given that my machine passes the first 4 arguments as registers,
I believe that this should work - however, it strikes me as potentially
non-portable on some stack machines.

What I really want is to construct an arg list and pass that to my
function call, but I can't figure how to do that.

Any help will be appreciated,
Ihor Kinal
att!cbnewsh!ijk



More information about the Comp.lang.c mailing list