nospam@nospam.com wrote:[color=blue]
> 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?[/color]
What book are you reading that doesn't explain passing arrays to
functions?
int func(double array[], int size)
{
int index;
/* calculate index somehow */
if (index > 0 && index < size)
array[size]; /* do something with the double */
return 42;
}
V