Your function accepting variable arguments should somehow say when it reaches the end of the variable arguments. This can be by analyzing information from fixed arguments (for example, an argument that tells you how many arguments were passed, or a format string that tells you which arguments should follow), or it could be an explicit sentinel value, such as a null pointer , at the end of the variable arguments.
You seem to want a major miracle; Sorry, but only minor miracles are available.
You can create your interfaces as follows:
int test1(int x, struct list *list) { ...code to handle adding x to arbitrary list... } int test0(int x) { return test1(x, &global_struct); }
Then you call test0() when you want to use the default list, and test1() when you want to specify a different list.
Note that test0() so simple that it is a good candidate for defining the C99 inline function.
If you used C ++, you could provide a function with a default argument or an overloaded function (two lists of arguments and implementations, as mentioned above, but with the same name). Of course, even more than in C, the use of global variables is deprecated in C ++.
source share