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

Reply

Join Date: Jul 2005
Posts: 6
Reputation: Giant is an unknown quantity at this point 
Solved Threads: 0
Giant Giant is offline Offline
Newbie Poster

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

 
0
  #1
Jul 8th, 2005
Hi all,

I am trying to malloc some memory and then pass the address of the first array into another function however I keep getting the same error (see thread name).

  1. Error:error C2664: cannot convert parameter 1 from 'float **__w64 ' to 'float *
  2.  

Here is a short version of my code that repeats the same error.

  1. void vGetPixelValueIntoArray(float *,const char*, s_Header*);
  2.  
  3. int main(int argc, char **argv) {
  4.  
  5.  
  6. float **ppfImageData = 0;/* a pointer to a series of 2d arrays */
  7. s_Filename *psFile;
  8. s_Header *psHeader;
  9. float *pfResFunc;
  10. size_t nCountI,nCountJ;
  11.  
  12. if(!(ppfImageData = (float **) malloc(psHeader->nPhotosToBeCounted))){
  13. fprintf(stderr, "Failed to allocate memory for imageMatrix array!\n");
  14. return NULL;
  15. }
  16.  
  17. nCountI = 0;
  18. vGetPixelValueIntoArray(&ppfImageData[nCountI], "c:\testfile.ppm", psHeader); //parameter 1 that causes the problems
  19.  
  20. for (nCountJ=0; nCountJ<psHeader->nPhotosToBeCounted; nCountJ++){
  21. free(ppfImageData[nCountJ]);
  22. }
  23. free(ppfImageData);
  24. return 0;
  25. }
  26. void vGetPixelValueIntoArray(float *pfImageData, const char* pccFilename, s_Header* psHeader ) {// returns NULL if error
  27. size_t nCounter, nSecondCounter;
  28. FILE *pFTemp_file;
  29. //float *pfImage;
  30.  
  31. psHeader->nWantedPixels = 5; //Hack to only take in certain amount of pixels
  32. if (!(pFTemp_file = fopen(pccFilename,"rb"))){ //open file
  33. fprintf(stderr, "Can't open file!\n");
  34. exit(-1);
  35. }
  36. if (!(pfImageData = (float *) malloc(psHeader->nWantedPixels))){ //malloc array for image data
  37. fprintf(stderr, "Failed to allocate memory in *pfGetPixelValueIntoArray");
  38. exit(-1); //cant return a null >???? need a error function
  39. }
  40. for(nSecondCounter=0;nSecondCounter<psHeader->nHeaderEnd;nSecondCounter++){fgetc(pFTemp_file);}
  41.  
  42. for (nCounter=0; nCounter<psHeader->nWantedPixels; nCounter++){
  43. pfImageData[nCounter] = (unsigned char) fgetc(pFTemp_file);
  44. //skip next two values are they make up the rgb pixel and are therefore not needed
  45. //only do this if there are pixels to jump over and if it is a 3 channel operation
  46. fgetc(pFTemp_file);
  47. fgetc(pFTemp_file);
  48. if (feof(pFTemp_file)) break;
  49. }
  50. fclose(pFTemp_file);
  51.  
  52. }

What happens in function vGetPixelValueIntoArray is not really important as its the call line for this in Main that causes the error .

Any advice would be appreciated.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,628
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 718
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

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

 
0
  #2
Jul 8th, 2005
>Here is a short version of my code that repeats the same error
I just get a bunch of syntax errors. How about posting something complete that we can cut/paste and compile? By the way, your code as it is is filled with problems.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 6
Reputation: Giant is an unknown quantity at this point 
Solved Threads: 0
Giant Giant is offline Offline
Newbie Poster

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

 
0
  #3
Jul 8th, 2005
  1. // OneChannelWin32.cpp : Defines the entry point for the console application.
  2. //
  3. #include <iostream>
  4. #include "stdio.h"
  5. #include "stdlib.h"
  6. #include "string.h"
  7. #include "ctype.h"
  8. using namespace std;
  9.  
  10.  
  11. //float *pfGetPixelValueIntoArray(const char*, s_Header*);
  12. void vGetPixelValueIntoArray(float *);
  13.  
  14. void vGetPixelValueIntoArray(float *pfImageData ) {// returns NULL if error
  15.  
  16. if (!(pfImageData = (float *) malloc(5))){ //malloc array for image data
  17. fprintf(stderr, "Failed to allocate memory in *pfGetPixelValueIntoArray");
  18. exit(-1); //cant return a null >???? need a error function
  19. }
  20.  
  21. }
  22.  
  23. int main() {
  24.  
  25. float **ppfImageData;/* a pointer to a series of 2d arrays */
  26. int photostobecounted=16, nCountJ=0;
  27.  
  28. if(!(ppfImageData = (float **) malloc(photostobecounted))){
  29. fprintf(stderr, "Failed to allocate memory for imageMatrix array!\n");
  30. return NULL;
  31. }
  32. vGetPixelValueIntoArray(&ppfImageData[0]); //so mallocing the first
  33.  
  34. // deallocate memory
  35. for (nCountJ=0; nCountJ<photostobecounted; nCountJ++){
  36. free(ppfImageData[nCountJ]);
  37. }
  38. free(ppfImageData);
  39. return 0;
  40. }

Hopefully that should compile[or at least give you the same error I am getting] for you, I shouldnt worry about the problems as I believe most of them were caused by me trying to shorten the code in the first place . Anyway have a go with this,

Cheers,
Giant
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,358
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

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

 
0
  #4
Jul 8th, 2005
  1. testpp.cpp:
  2. Error E2209 testpp.cpp 3: Unable to open include file 'stdafx.h'
  3. Error E2268 testpp.cpp 11: Call to undefined function 'malloc' in function vGetPixelValueIntoArray(float *)
  4. Warning W8060 testpp.cpp 11: Possibly incorrect assignment in function vGetPixelValueIntoArray(float *)
  5. Error E2268 testpp.cpp 12: Call to undefined function 'fprintf' in function vGetPixelValueIntoArray(float *)
  6. Error E2451 testpp.cpp 12: Undefined symbol 'stderr' in function vGetPixelValueIntoArray(float *)
  7. Error E2268 testpp.cpp 13: Call to undefined function 'exit' in function vGetPixelValueIntoArray(float *)
  8. Warning W8057 testpp.cpp 16: Parameter 'pfImageData' is never used in function vGetPixelValueIntoArray(float *)
  9. Error E2268 testpp.cpp 23: Call to undefined function 'malloc' in function main(int,char * *)
  10. Error E2451 testpp.cpp 24: Undefined symbol 'stderr' in function main(int,char * *)
  11. Error E2268 testpp.cpp 24: Call to undefined function 'fprintf' in function main(int,char * *)
  12. Error E2451 testpp.cpp 25: Undefined symbol 'NULL' in function main(int,char * *)
  13. Error E2034 testpp.cpp 27: Cannot convert 'float * *' to 'float *' in function main(int,char * *)
  14. Error E2342 testpp.cpp 27: Type mismatch in parameter 'pfImageData' (wanted 'float *', got 'float * *') in function main(int,char * *)
  15. Error E2268 testpp.cpp 31: Call to undefined function 'free' in function main(int,char * *)
  16. Warning W8013 testpp.cpp 31: Possible use of 'ppfImageData' before definition in function main(int,char * *)
  17. Warning W8057 testpp.cpp 35: Parameter 'argc' is never used in function main(int,char * *)
  18. Warning W8057 testpp.cpp 35: Parameter 'argv' is never used in function main(int,char * *)
  19. *** 12 errors in Compile ***
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 6
Reputation: Giant is an unknown quantity at this point 
Solved Threads: 0
Giant Giant is offline Offline
Newbie Poster

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

 
0
  #5
Jul 8th, 2005
sorry bout that, forgot about header file, it _should_ work now (he said with vast amounts of hope), I editted my last post to incorporate some changes.

giant.

p.s. can i ask what development software/compiler/environments you use ?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,358
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

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

 
0
  #6
Jul 8th, 2005
vGetPixelValueIntoArray(&ppfImageData[0]); //so mallocing the first
Since &ppfImageData[0] is the same as ppfImageData, which is a float**, and since vGetPixelValueIntoArray receives a float*, do you instead mean to write this?
vGetPixelValueIntoArray(ppfImageData[0]); //so mallocing the first
[edit]And use angle brackets for standard headers.
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "ctype.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
[edit2]Why use so much C in a C++ source?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 6
Reputation: Giant is an unknown quantity at this point 
Solved Threads: 0
Giant Giant is offline Offline
Newbie Poster

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

 
0
  #7
Jul 8th, 2005
Originally Posted by Dave Sinkula
vGetPixelValueIntoArray(&ppfImageData[0]); //so mallocing the first
Since &ppfImageData[0] is the same as ppfImageData, which is a float**, and since vGetPixelValueIntoArray receives a float*, do you instead mean to write this?
vGetPixelValueIntoArray(ppfImageData[0]); //so mallocing the first
No, I don't, I want to pass the address of the first pointer. In the full program I go through all the malloced memory address but i was trying to isolate the problem so only passed in the first address, it could easily have been the 5th adress.


[edit2]Why use so much C in a C++ source?
I am using visual studio and thats how it saved it, it _is_ meant to be written in C, though I know some C++ may have slipped in as VS lets you away with it, it has to be noted at this point that I am fairly incompetent at programming (as I have only been using vs2003 and C/C++ for 6 weeks now), and am just coming back from a year out of anything remotely thought provoking :/.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,358
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

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

 
0
  #8
Jul 8th, 2005
Originally Posted by Giant
Originally Posted by Dave Sinkula
vGetPixelValueIntoArray(&ppfImageData[0]); //so mallocing the first
Since &ppfImageData[0] is the same as ppfImageData, which is a float**, and since vGetPixelValueIntoArray receives a float*, do you instead mean to write this?
vGetPixelValueIntoArray(ppfImageData[0]); //so mallocing the first
No, I don't, I want to pass the address of the first pointer. In the full program I go through all the malloced memory address but i was trying to isolate the problem so only passed in the first address, it could easily have been the 5th adress.
I just found out this is cross-posted (Quzah gave you the same answer right away too).

Think about this some more:
Since &ppfImageData[0] is the same as ppfImageData, which is a float**, and since vGetPixelValueIntoArray receives a float*
Originally Posted by Giant
I am using visual studio and thats how it saved it, it _is_ meant to be written in C, though I know some C++ may have slipped in as VS lets you away with it, it has to be noted at this point that I am fairly imcompetent at programming (as I have only been using vs2003 and C/C++ for 6 weeks now), and am just coming back from a year out of anything remotely thought provoking :/.
Save it as a .c file so you can compile as C and save yourself from added confusion.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 6
Reputation: Giant is an unknown quantity at this point 
Solved Threads: 0
Giant Giant is offline Offline
Newbie Poster

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

 
0
  #9
Jul 8th, 2005
okay if I do just simply write
  1. ppfImageData[0]
surely I am only passing a value to the function, rather than the address of first pointer, which I need.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,358
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

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

 
0
  #10
Jul 8th, 2005
Let me take a different tack. It seems like you are trying for something along this line.
#include <stdio.h>
#include <stdlib.h>

void foo(float **array2d, size_t index)
{
   array2d[index] = malloc(5 * sizeof *array2d[index]);
}

int main()
{
   size_t i, j, size = 16;
   float value = 0, **array2d = malloc(size * sizeof *array2d);
   if ( array2d )
   {
      for ( i = 0; i < size; ++i )
      {
         foo(array2d, i);
         if ( !array2d[i] )
         {
            fprintf(stderr, "Failed to allocate memory for array!\n");
            goto cleanup;
         }
         for ( j = 0; j < 5; ++j )
         {
            array2d[i][j] = ++value;
         }
      }
      for ( i = 0; i < size; ++i )
      {
         for ( j = 0; j < 5; ++j )
         {
            printf("array2d[%d][%d] = %g\n", (int)i, (int)j, array2d[i][j]);
         }
      }
   cleanup:
      for ( j = i, i = 0; i < j; ++i )
      {
         free(array2d[i]);
      }
      free(array2d);
   }
   return 0;
}
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC