Aside from hacking up some architecture/compiler dependent assembly, is it possible to do something like this using either straight C or a macro, and expand out a variable length array into the argument list:
void myFunc (int a, int b, int c, int d);
void myOtherFunc (int a, int b);
/* try to call them */
int args[4] = { 1, 2, 3, 4 };
myFunc (SOME_MAGIC (args));
int otherArgs[2] = { 1, 2 };
myOtherFunc (SOME_MAGIC (otherArgs));
Apologies if this is a duplicate; basically every variation on search terms I tried had a question about passing arrays between functions, not messing with the function stack.
It's OK to assume that the argument count passed to the function will always match the prototype. Otherwise, I suppose an argc/argv style thing is really the only way to go?
Another example, hopefully with a little more context:
const struct func_info table[NUM_FUNCS] = {
{ foo, 1, true },
{ bar, 2, true },
// ...
}
struct func_info fi = table[function_id];
int args* = malloc (fi->argc * sizeof (int));
for (int i = 0; i < fi->argc; i++) {
args[i] = GetArgument (i);
}
fi->func (SOME_MAGIC (args));