Originally Posted by
TheBigH
I'm not sure I understand. I should be able to call phi0 from within solve_simul if I have a pointer to it, and pointers to all the variables it needs. And I do have all those things, but I don't know the length of phi0's argument list before I call solve_simul.
You haven't thought it all the way through. Try actually writing code to do that and you'll see the problem.
This is clearly a job for arrays, not variable argument lists. It's just too ugly with varargs:
Code:
#include <stdio.h>
#include <stdarg.h>
typedef void (*PFUNC)(int n, va_list *va);
void solve_simul(int n, ...) {
int i;
va_list va1, va2;
va_start(va1, n);
for (i = 0; i < n; i++) // step va1 past doubles
va_arg(va1, double);
for (i = 0; i < n; i++) {
va_start(va2, n);
va_arg(va1, PFUNC)(n, &va2);
va_end(va2);
}
va_end(va1);
}
void f1(int n, va_list *va) {
int i;
printf("f1\n");
for (i = 0; i < n; i++)
printf("%f\n", va_arg(*va, double));
}
void f2(int n, va_list *va) {
int i;
printf("f2\n");
for (i = 0; i < n; i++)
printf("%f\n", va_arg(*va, double));
}
int main() {
solve_simul(2, 1.0, 2.0, f1, f2);
return 0;
}
As for using arrays, the declaration of solve_simul would be something like:
Code:
void solve_simul(int n, double *vars, double (*phis)(int , double *));