incompatible pointer type.

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

  1. farmerdoug macrumors 6502a

    Joined:
    Sep 16, 2008
    #1
    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

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    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

    Joined:
    Sep 16, 2008
    #3
    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

    Sydde

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

    plinden

    Joined:
    Apr 8, 2004
    #5
    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

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #6
    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
     
  7. farmerdoug thread starter macrumors 6502a

    Joined:
    Sep 16, 2008
    #7
    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;
    	
    }
    
    
     
  8. farmerdoug thread starter macrumors 6502a

    Joined:
    Sep 16, 2008
    #8
    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.
     

Share This Page