I’m trying to use the GSL library to solve ODE and I’m having some difficulty using the void pointer
I need to send a parameter over that supposed to contain an array of an array:
double k1[2][4];
which gets sent to
gsl_odeiv_system sys = {func, jac, 2, &k1};
this gets passed on to both func and jac as *params
int func (double t, const double y[], double f[], void *params)
in func, I’m trying to extract k1 via:
double k1[2][4];
k1 = *(double[][])params;
or
k1 = (double[][])params;
or…
k1 = *(double *)params;
etc
I guess the question is: is there a one line solution?
I don’t think you can cast to an array type (a multidimensional array) like this. You may need to declare a temporary variable to hold the pointer to the first element of the array.
Of course, you need to specify the number of elements per row for this to work. Otherwise the compiler does not know how to access elements in the resulting array (remember that
x[i][j]is converted internally to*(x + i*n + j)wherenis the number of elements in each row).I.e.
By the way, you don’t have to use
&k1when passing the array to the function. The name of the array may be used as its address (A pointer to the first element).