expected 'double **' but argument is of type 'double (*)[2]'

Viewed 4282

I encountered this strange behavior in C.

This code gives me the compile warning:

expected 'double **' but argument is of type 'double (*)[2]'

What is the problem? An array of doubles is a pointer to double, right?

BTW, if I send the array itself, the assignment doesn't affect the values and I don't know why.

#include <stdio.h>

void set1(double **x)
{
    (*x)[0] = (*x)[1] =1.0;
}

int main()
{
    double x[2];
    set1(&x);
    printf("%d\n%d\n",x[0],x[1]);
}
4 Answers

If you explicitly convert the type in the function call as follows set1((double **)&x); the warning will go away

Related