So, I have a function that accepts a variable number of arguments and va_start's a va_list. It then creates a struct, assigns that va_list to one of the members, and then stores that struct globally. An undetermined time later, a function in that struct is called with the va_list, va_end is called at the end of it, and then the object is destroyed. My problem is that the function that creates the va_list does not seem to be creating a new one each time it is called... For example:
The struct initializing function is called with (15,2), then it is called again with (3,4). When the two struct's functions are later executed, the data used is 3, 4 for both of them. What's happening, and, more importantly, how do I fix it?
This function creates the task:
Code:
void new_task(double time_till_execution, void (*function)(va_list), ...)
{
// Argument list generation
va_list arguments;
va_start(arguments,function);
// Instance initialization
task task_p;
task_p.func = function;
task_p.args = arguments;
queue.push(task_p);
}
This function executes the task:
Code:
void task_execute(task const t) { // Function to execute the task
t.task(t.args);
}
And this is an example of a function called:
Code:
void func_1(va_list arguments)
{
int x = va_arg(arguments,int);
int y = va_arg(arguments,int);
cout<< x << " " << y << "\n\n";
}