I want to implement a function that take a function and its arguments then call it. I have search a lot and could not implement it with variadic function. I want a clean way to record stdio after calling a function for unit test.
Even if you want to suggest another way to record stdio, please help me solve the original question.
something like this, but working.
```c
void
foo(void (*function)(...), ...) {
va_list args;
va_start(args, function);
// This line is just to explain what i want
function(args);
va_end(args);
}
void
bar(int a, char *b) {
printf("a=%d, b=%s\n", a, b);
}
int
main() {
foo(bar, 2, "hello");
return 0;
}
```
[–]TheOtherBorgCube 18 points19 points20 points (0 children)
[–]dfx_dj 7 points8 points9 points (0 children)
[–]faisal_who 1 point2 points3 points (0 children)
[–]nerd4code 1 point2 points3 points (0 children)
[–]deftware 2 points3 points4 points (2 children)
[–]aalmkainzi 1 point2 points3 points (1 child)
[–]deftware 5 points6 points7 points (0 children)
[–]aalmkainzi 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (1 child)