A routine calls for a float ** but in the calling routine, everything is defined as a float*. Is there a way to cast the float * so as to not get an incompatible pointer type error.
A routine calls for a float ** but in the calling routine, everything is defined as a float*. Is there a way to cast the float * so as to not get an incompatible pointer type error.
Look more closely at how the 2nd post is worded:I guess my terseness has gotten me again.
I have an array defined as a float * that is several times bigger than the array wanted by the subroutine where an array is defined as a float**
I want to send a portion of my float* to the subroutine. I think memcpy will work as intermediate step with an intermediate variable. Yes? Is there an easier way.
gnasher729 said:A float** is a pointer to a location in memory where a float* is stored.
So if you have a float* somewhere, how do you get a pointer to the location where it is stored ?????&&&&&&??????
I guess my terseness has gotten me again.
I have an array defined as a float * that is several times bigger than the array wanted by the subroutine where an array is defined as a float**
if ((cys1 = (float *)calloc(waves*reduced_image*2 ,sizeof(float))) == NULL)
{
printf("no cys1 memory\n");
exit(0);
}
void splin2(float x1a[], float x2a[], float **ya, float **y2a, int m, int n, float x1, float x2, float *y)
{
void spline (float x[], float y[], int n, float yp1, float ypn, float y2[]);
void splint(float xa[], float ya[], float y2a[], int n, float x, float *y);
int j;
float *ytmp, * yytmp;
ytmp = (float *) calloc(m, sizeof(float));
yytmp = (float *) calloc(m, sizeof(float));
for ( j = 0; j < m; j++){
splint(x2a,ya[j],y2a[j],n,x2,&yytmp[j]);
// printf("%f\n", yytmp[j]);
}
spline(x1a, yytmp,m,1.0e30, 1.0e30, ytmp);
// for ( j = 0; j < m; j++)
// printf("%f %f \n",x1a[j], ytmp[j]);
splint(x1a,yytmp,ytmp,m,x1,y);
free(ytmp);
free(yytmp);
}
void splint(float xa[], float ya[], float y2a[], int n, float x, float *y)
{
int klo,khi,k;
float h,b,a;
klo=1 - 1;
khi=n - 1;
while (khi-klo > 1) {
k=(khi+klo) >> 1;
if (xa[k] > x) khi=k;
else klo=k;
} //klo and khi now bracket the input value of x.
h=xa[khi]-xa[klo];
if (h == 0.0) printf("Bad xa input to routine splint %d %f %d %f\n", khi, xa[khi], klo, xa[klo]); //The xa's must be distinct.
a=(xa[khi]-x)/h;
b=(x-xa[klo])/h; //Cubic spline polynomial is now evaluated.
*y=a*ya[klo]+b*ya[khi]+((a*a*a-a)*y2a[klo]+(b*b*b-b)*y2a[khi])*(h*h)/6.0;
}
for ( row = 0; row < rows; row++)
memcpy(ya[row], cyy1 + row*rows, sizeof(float)*cols);