G
Guest
Hello!
I can pass a "pointer to a double" to a function that accepts
double*, like this:
int func(double* var) {
*var=1.0;
...
}
double var;
n=func(&var);
---
Now I want to pass a pointer to an array of doubles, the size
of the array must not be fixed though:
int func(double[]* array) {
int index;
index=3;
array[index]=1.0;
...
}
double array[100];
n=func(&array);
with the above code the compiler gives me an error. The only
solution that I found so far is this very inelegant one:
int func(void* array) {
int index;
index=3;
*((double*)(array)+index)=1.0;
...
}
double array[100];
n=func(&array);
---
There must be a cleaner way.. but what is it?
I am interested in both C and "C++ only" solutions.
Thanks!
Mike
I can pass a "pointer to a double" to a function that accepts
double*, like this:
int func(double* var) {
*var=1.0;
...
}
double var;
n=func(&var);
---
Now I want to pass a pointer to an array of doubles, the size
of the array must not be fixed though:
int func(double[]* array) {
int index;
index=3;
array[index]=1.0;
...
}
double array[100];
n=func(&array);
with the above code the compiler gives me an error. The only
solution that I found so far is this very inelegant one:
int func(void* array) {
int index;
index=3;
*((double*)(array)+index)=1.0;
...
}
double array[100];
n=func(&array);
---
There must be a cleaner way.. but what is it?
I am interested in both C and "C++ only" solutions.
Thanks!
Mike