S
steve
Hey guys,
I have a delemna which I can't figure out.
This is regarding "void pointers" and I confess, I really don't
understand them nearly enough to even understand what the problem is.
I'm using a "void" type array as an instrument to hold parameters of
non-pre-determined types,
like so:
Then I setup my data parameters similar to this:
I can then assign my data values, to the array,
like so:
These two methods compile just fine and work as expected.
However, this statement will not compile:
and generates this compiler error:
"...cast from 'double' to 'pointer to void' is illegal"
When it's all said and done, the idea is to pass the data referred to
in the array as function parameters,
like so:
MyFunction(params[0], params[1], etc.);
Does sombody understand void pointers enough to explain why the above
doesn't work and possibly offer a solution to the problem.
Thanks,
Steve
I have a delemna which I can't figure out.
This is regarding "void pointers" and I confess, I really don't
understand them nearly enough to even understand what the problem is.
I'm using a "void" type array as an instrument to hold parameters of
non-pre-determined types,
like so:
Code:
void * params[5];
Then I setup my data parameters similar to this:
Code:
int int_param_values[5] = {1,2,3,4,5};
char **str_param_values;
str_param_values = malloc(5 * sizeof(char *));
str_param_values[0] = malloc(10 * sizeof(char));
strcpy(str_param_values[0], "hello");
double dbl_param_values[5] = {1.1, 2.2, 3.3};
I can then assign my data values, to the array,
like so:
Code:
params[indx] = (void*)int_param_values[ndx];
//-or-
params[indx] = (void*)str_param_values[ndx];
These two methods compile just fine and work as expected.
However, this statement will not compile:
Code:
params[indx] = (void*)dbl_param_values[ndx];
and generates this compiler error:
"...cast from 'double' to 'pointer to void' is illegal"
When it's all said and done, the idea is to pass the data referred to
in the array as function parameters,
like so:
MyFunction(params[0], params[1], etc.);
Does sombody understand void pointers enough to explain why the above
doesn't work and possibly offer a solution to the problem.
Thanks,
Steve