Expected ‘double *’ but argument is of type ‘double **’

3.5k views Asked by At

Hello everyone and thanks in advance. Im trying to write a function in C for Gauss-Legendre quadrature - numerical method for integrating - and I have to apply it for 2 cases, one whose interval is converted to [-1,1] and another case whose interval is yet divided again in four parts. As both uses the same tabled numbers for the weights and abscissas, I have made arrays for both, and the only difference between them would be the function for dividing(or redividing) the interval. The thing is that, as for each I will have different applications on the function I want to integrate (which is in case erf) and different multipliers (I won t go in detail, it is intrinsic mathematical part of the method) I`ve a function:

void adapt(double a, double b, double *ptrt, double *ptrm, double x)
{
   *ptrt=1/2*(x*(b-a)+a+b);
   *ptrm=(b-a)/2;
}

Where a and b stands for the beggingin and the ending of the original interval, x for the the tabled gauss-legendre value of x and the the pointers would return numbers I need to use in the formulae at the quadrature function:

double gauss(double a, double b)
{
int i;
double I, t, m,  p[16],  x[16];
double *ptrt, *ptrm;
ptrt=&t;
ptrm=&m;
I=t=m=0.0;
x[1]=0.0000000000000000; x[2]=-0.2011940939974345; x[3]=0.2011940939974345;
x[4]=-0.3941513470775634; x[5]=0.3941513470775634; x[6]=-0.5709721726085388;
x[7]=0.5709721726085388; x[8]=-0.7244177313601701; x[9]=0.7244177313601701;
x[10]=-0.8482065834104272; x[11]=0.8482065834104272; x[12]=-0.9372733924007060 ;
x[13]=0.9372733924007060; x[14]=-0.9879925180204854; x[15]=0.9879925180204854 ;

p[1]=0.2025782419255613; p[2]=0.1984314853271116; p[3]=0.1984314853271116;
p[4]=0.1861610000155622; p[5]=0.1861610000155622; p[6]=0.1662692058169939;
p[7]=0.1662692058169939; p[8]=0.1395706779261543; p[9]=0.1395706779261543;
p[10]=0.1071592204671719; p[11]=0.1071592204671719; p[12]=0.0703660474881081;
p[13]=0.0703660474881081; p[14]=0.0307532419961173; p[15]=0.0307532419961173;

for(i=1;i<=15;i++)
    {
            adapt(a, b, &ptrt, &ptrm, x[i]);
            if(a=0.0 && b=XF) I=I+C*m*(p[i]*dfunc(t));
            else I=I+C*m*XF/2*(p[i]*dfunc(XF/2*(t+1));

    }
return I;
}

I wont post the main function here because it just prints and say stuff about the returns which are not important. My problem is that it keeps giving the messages:

"EP3.c:140:4: warning: passing argument 3 of ‘adapt’ from incompatible pointer type [enabled by default] adapt(a, b, &ptrt, &ptrm, x[i]);

EP3.c:16:6: note: expected ‘double *’ but argument is of type ‘double **’ void adapt(double a, double b, double *ptrt, double *ptrm, double x)"

and the same for the other pointer. I can`t understand why does the compiler understands this pointers are "pointers to pointers"

I have looked thru the code dozens of times and cant find the reason. Sorry for any mistake, first time here =)

1

There are 1 answers

0
Sourav Kanta On

ptrm points to address of m(double). So ptrm is of double * type. In the function call you pass address of ptrm so it becomes of type double **. Therefore in your function call pass pointers only.

 adapt(a, b, ptrt, ptrm, x[i]);