Thread: error C2664: cannot convert parameter 1 from float** __w64 to float *

  1. #1
    Yes, I play CounterStrike
    Join Date
    Jun 2005
    Location
    Edinburgh, Scotland
    Posts
    33

    error C2664: cannot convert parameter 1 from float** __w64 to float *

    Hi,

    simply put the following code generates the error
    Code:
    error C2664: 'vGetPixelValueIntoArray' : cannot convert parameter 1 from 'float **__w64  ' to 'float *'
    Code:
    int main(int argc, char **argv) {
       
    float **ppfImageData;/* a pointer to a series of 2d arrays */
    s_Filename *psFile;
    s_Header *psHeader;
    	
    psFile = (struct s_Filename *) malloc(sizeof(s_Filename));
    psHeader = (struct s_Header *) malloc(sizeof(s_Header));
    
    if (argc < 2){strncpy(acFilename, "C:\\Documents and Settings\\matt smith\\Desktop\\example\\img0061.ppm", sizeof(acFilename));}
    else {strncpy(acFilename,argv[1],sizeof(acFilename));}
    
    psFile = psGetImageBase(acFilename, psFile); //not important
    psHeader = psGetHeader(psFile->acNextFileName, psHeader); //not important
    
    psHeader->nPhotosToBeCounted = psFile->nMaxImagenumber;
    
    	if(!(ppfImageData = (float **) malloc(psHeader->nPhotosToBeCounted))){
            fprintf(stderr, "Failed to allocate memory for imageMatrix array!\n");
    		return NULL;
    	}
    
    vGetPixelValueIntoArray(&ppfImageData[nCountI], psFile->acNextFileName, psHeader); //this is the line that causes the error (the &ppfImageData is the problem variable)
    
    }
    
    void vGetPixelValueIntoArray(float *pfImageData, const char* pccFilename, s_Header* psHeader ) {// returns NULL if error 
        size_t nCounter, nSecondCounter;
        FILE *pFTemp_file;
    
    	psHeader->nWantedPixels = 5;
    
    	if (!(pfImageData = (float *) malloc(psHeader->nWantedPixels))){ //malloc array for image data
            fprintf(stderr, "Failed to allocate memory in *pfGetPixelValueIntoArray");
            exit(-1);
        }	
    }
    I have looked into this problem and it could be a win32 problem but I have tried all of the suggestions about pre-processing I could find, was wondering if anyone had any ideas where I was going wrong...


    Cheers,
    Giant

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Consider:
    Code:
    void foo( int *bar );
    Now if you want to pass an integer to this you do this:
    Code:
    int baz;
    
    foo( &baz );
    And if we want to pass an actual pointer pointer:
    Code:
    int *baz;
    
    foo( baz );
    And if we're going from a pointer to a pointer:
    Code:
    int **baz;
    
    foo( *baz );
    And if we're pretending our two pointers are an array:
    Code:
    int **baz;
    
    foo( baz[ x ] );
    Do you see your problem now?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Yes, I play CounterStrike
    Join Date
    Jun 2005
    Location
    Edinburgh, Scotland
    Posts
    33
    erm... no sorry, can you take out the large stick of education and hit me with it please

    from what I think you are saying I should pass
    Code:
    vGetPixelValueIntoArray(ppfImageData[nCountI], psFile->acNextFileName, psHeader);
    instead of
    Code:
    vGetPixelValueIntoArray(&ppfImageData[nCountI], psFile->acNextFileName, psHeader);

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If this is C, why are all those casts there?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Yes, I play CounterStrike
    Join Date
    Jun 2005
    Location
    Edinburgh, Scotland
    Posts
    33
    define 'all those casts' ?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well "all those casts" are on the return result of malloc.
    In C,
    psFile = malloc(sizeof(s_Filename));
    Is all you need.

    If you're getting warnings, then tell us what they are and we'll tell you how to fix it. Don't just sweep the warnings under the carpet to make them go away.

    Just so we're straight, you want vGetPixelValueIntoArray to allocate some memory for a row of your array, and you want ppfImageData[nCountI] to be assigned the result of that malloc?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Yes, I play CounterStrike
    Join Date
    Jun 2005
    Location
    Edinburgh, Scotland
    Posts
    33
    yes thats what i want to do and I have no warnings at all, just the error line

    Giant.

    [EDIT] When I take out the casts the compiler fails on all three counts saying ''cannot convert from void* to <insert cast here>''

    I am using visual studio 2003 btw, incase thats important

    [/EDIT]
    Last edited by Giant; 07-08-2005 at 08:36 AM.

  8. #8
    Yes, I play CounterStrike
    Join Date
    Jun 2005
    Location
    Edinburgh, Scotland
    Posts
    33
    i have shortened the code to isolate the problem to this:

    Code:
    // OneChannelWin32.cpp : Defines the entry point for the console application.
    //
    #include <iostream>
    #include "stdio.h"
    #include "stdlib.h"
    #include "string.h"
    #include "ctype.h"
    using namespace std;
    
    
    //float *pfGetPixelValueIntoArray(const char*, s_Header*);
    void vGetPixelValueIntoArray(float *);
    
    void vGetPixelValueIntoArray(float *pfImageData ) {// returns NULL if error 
    
    	if (!(pfImageData = (float *) malloc(5))){ //malloc array for image data
            fprintf(stderr, "Failed to allocate memory in *pfGetPixelValueIntoArray");
            exit(-1); //cant return a null >???? need a error function
        }	
    	
    }
    
    int main() {
       
    	float **ppfImageData;/* a pointer to a series of 2d arrays */
    	int photostobecounted=16, nCountJ=0;
    	
    	if(!(ppfImageData = (float **) malloc(photostobecounted))){
            fprintf(stderr, "Failed to allocate memory for imageMatrix array!\n");
    		return NULL;
    	}
    		vGetPixelValueIntoArray(&ppfImageData[0]); //so mallocing the first
    
    	// deallocate memory 
    	for (nCountJ=0; nCountJ<photostobecounted; nCountJ++){
    			free(ppfImageData[nCountJ]);
        }
        free(ppfImageData);
        return 0;
    }

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > saying ''cannot convert from void* to <insert cast here>''
    Yeah, that means you're using a C++ compiler to compile C code.
    1. rename your files to be .c files (not .cpp files)
    2. start using C++ properly and call new/delete to allocate memory, not malloc/free

    But I see from your code, it's more C++ than C

    Given your call, try this
    Code:
    void vGetPixelValueIntoArray(float **);
    
    void vGetPixelValueIntoArray(float **pfImageData ) {// returns NULL if error 
        float *temp;
        if ( ! (temp = malloc(5*sizeof(*temp)) ) )
            fprintf(stderr, "Failed to allocate memory in *pfGetPixelValueIntoArray");
        *pfImageData = temp;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Opengl walking leg animation
    By Bobby230 in forum C Programming
    Replies: 3
    Last Post: 03-05-2006, 03:41 PM
  2. Replies: 6
    Last Post: 11-12-2005, 11:57 AM
  3. Display list not displaying?
    By psychopath in forum Game Programming
    Replies: 5
    Last Post: 09-19-2004, 06:47 PM
  4. help w/another program!!!
    By edshaft in forum C++ Programming
    Replies: 2
    Last Post: 12-17-2001, 11:34 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM