incompatible pointer type.

Discussion in 'Mac Programming' started by farmerdoug, Feb 26, 2010.

  1. farmerdoug macrumors 6502a

    Sep 16, 2008
    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.
  2. gnasher729 macrumors P6


    Nov 25, 2005
    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 ?????&&&&&&??????
  3. farmerdoug thread starter macrumors 6502a

    Sep 16, 2008
    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.
  4. Sydde macrumors 68020


    Aug 17, 2009
    Look more closely at how the 2nd post is worded:
  5. plinden macrumors 68040


    Apr 8, 2004
    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.
  6. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    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.

  7. farmerdoug thread starter macrumors 6502a

    Sep 16, 2008
    Does this help?

    I have to send a part of cys1 to splin2 where it calls for **ya
     if ((cys1 = (float *)calloc(waves*reduced_image*2 ,sizeof(float))) == NULL)
                printf("no cys1 memory\n");
    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++){
    		//	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]);
    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.
    	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. 
    	b=(x-xa[klo])/h;			//Cubic spline polynomial is now evaluated.
  8. farmerdoug thread starter macrumors 6502a

    Sep 16, 2008
    Using this intermediate step, the code complies. Now lets see if it runs. Or should I go back and refine cyy1?

    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.

Share This Page