You can look into variable-length argument lists (example
here), which is similar to how "printf", "scanf", etc, work. I've never implemented one of these functions, but a quick read on a different site says that there is no information about the type and number of subsequent arguments, so from that to me it seems you can pass your different types TYPE_A, TYPE_B, etc.
Alternatively, you can wrap the arguments in a structure (excuse any syntax errors)
Code:
struct arg_type
{
char foo_set;
int foo;
char bar;
char bar_set;
};
void f(struct arg_type args)
{
if ( args.foo_set)
{
// do something with args.foo
}
// etc...
}
int main(void)
{
struct arg_type args;
args.foo_set = 1;
args.foo = 42;
f(args);
}
Maybe you could use a "void*[MAX_ARG_LENGTH]", and only populate the relevant index if that argument is "set" or "passed". For example
Code:
// map argument types to specific constant indices
const int INDEX_FOO = 2;
const int INDEX_BAR = 5;
// etc.
const itn MAX_ARG_LENGTH=42;
void foo(void* args[MAX_ARG_LENGTH])
{
if (args[INDEX_FOO) != null)
{
// do something with arg 'foo'
}
// etc
}
int main(void)
{
void* args[MAX_ARG_LENGTH];
// "pass" value for only "foo"
int foo = 1234;
args[INDEX_FOO] = &foo;
f(args);
}