Thanks guys for the aswer. To be precise I explain you my problem. I want to build my own header with some optimization functions. As you probably know an optimization function is "general" and what changes is the function to optimize over.
Here is some sample code (parabola is only a toy function) where "Bustra_zeroin" is a zero-finder routine.
Code:
struct opt_args{
double *data;
int length_data;
};
static double parabola(double x, struct opt_args *args)
{
int i;
double res;
for(i=0;i<args->length_data;i++)
{
res+= args->data[i]*pow(x,2)-2;
}
return(res);
}
double Bustra_zeroin( /* An estimate of the root */
double *ax1, /* Left border | of the range */
double *bx1, /* Right border| the root is seeked*/
double *Tol, /* Acceptable tolerance */
int *Maxit, /* Max # of iterations */
double (*f)(double, struct opt_args *args),/* Function under investigation */
struct opt_args *args /* Other arguments for f*/
)
{
.....
.....
fa = (*f)(a, args);
fb = (*f)(b, args);
.....
....
}
Hence you see that once you build up your function it must have as a first argument the parameter to optimize over and as a second one a pointer to a structure in order to pass the optional arguments of the function. My concern is to be able to build "Bustra_zeroin" in such a way that the user does not have to edit it to pass his own arguments. The only task that the user must do is to write his own function. As you see, if you use "Bustra_zeroin" you must edit it to specificy the name of the structure pointed.
Do you understand my problem? Is there, maybe, another smart way to cope with this?
I apologize for my terrible english!