Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
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.

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**

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.
 
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.
Look more closely at how the 2nd post is worded:
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**

I'm having difficulty understanding this. My impression from your first post was that the float** is an input parameter to the function, but I don't see how a well written function would restrict this to be a certain size. Can you post some sample code?

As for avoiding the incompatible pointer type error, it's already been strongly hinted at, but if you're still having difficulties understanding it you should revise the pointers chapter of whatever book you're using.
 
I really have no idea what the destination function does with the float **. Is this a list of float *s, that just point to one float on the other side, or is it an array of float arrays? How you do this would definitely vary, but you may need to make an array the size you need of float *, then loop over the floats you want to send, getting their address with & and assigning them to your new array. If it's a two dimensional array, that will be more involved.

-Lee
 
Does this help?

I have to send a part of cys1 to splin2 where it calls for **ya
Code:
 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;
	
}
 
Using this intermediate step, the code complies. Now lets see if it runs. Or should I go back and refine cyy1?

Code:
for ( row = 0; row < rows; row++)
    memcpy(ya[row], cyy1 + row*rows, sizeof(float)*cols);

What I don't understand it that either way the subroutine is getting an address.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.