| | |
error C2664: cannot convert parameter 1 from 'float **__w64 ' to 'float *'
![]() |
•
•
Join Date: Jul 2005
Posts: 6
Reputation:
Solved Threads: 0
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).
Here is a short version of my code that repeats the same error.
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.
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).
C Syntax (Toggle Plain Text)
Error:error C2664: cannot convert parameter 1 from 'float **__w64 ' to 'float *
Here is a short version of my code that repeats the same error.
C Syntax (Toggle Plain Text)
void vGetPixelValueIntoArray(float *,const char*, s_Header*); int main(int argc, char **argv) { float **ppfImageData = 0;/* a pointer to a series of 2d arrays */ s_Filename *psFile; s_Header *psHeader; float *pfResFunc; size_t nCountI,nCountJ; if(!(ppfImageData = (float **) malloc(psHeader->nPhotosToBeCounted))){ fprintf(stderr, "Failed to allocate memory for imageMatrix array!\n"); return NULL; } nCountI = 0; vGetPixelValueIntoArray(&ppfImageData[nCountI], "c:\testfile.ppm", psHeader); //parameter 1 that causes the problems for (nCountJ=0; nCountJ<psHeader->nPhotosToBeCounted; nCountJ++){ free(ppfImageData[nCountJ]); } free(ppfImageData); return 0; } void vGetPixelValueIntoArray(float *pfImageData, const char* pccFilename, s_Header* psHeader ) {// returns NULL if error size_t nCounter, nSecondCounter; FILE *pFTemp_file; //float *pfImage; psHeader->nWantedPixels = 5; //Hack to only take in certain amount of pixels if (!(pFTemp_file = fopen(pccFilename,"rb"))){ //open file fprintf(stderr, "Can't open file!\n"); exit(-1); } if (!(pfImageData = (float *) malloc(psHeader->nWantedPixels))){ //malloc array for image data fprintf(stderr, "Failed to allocate memory in *pfGetPixelValueIntoArray"); exit(-1); //cant return a null >???? need a error function } for(nSecondCounter=0;nSecondCounter<psHeader->nHeaderEnd;nSecondCounter++){fgetc(pFTemp_file);} for (nCounter=0; nCounter<psHeader->nWantedPixels; nCounter++){ pfImageData[nCounter] = (unsigned char) fgetc(pFTemp_file); //skip next two values are they make up the rgb pixel and are therefore not needed //only do this if there are pixels to jump over and if it is a 3 channel operation fgetc(pFTemp_file); fgetc(pFTemp_file); if (feof(pFTemp_file)) break; } fclose(pFTemp_file); }
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.
•
•
Join Date: Jul 2005
Posts: 6
Reputation:
Solved Threads: 0
C Syntax (Toggle Plain Text)
// 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; }
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
C Syntax (Toggle Plain Text)
testpp.cpp: Error E2209 testpp.cpp 3: Unable to open include file 'stdafx.h' Error E2268 testpp.cpp 11: Call to undefined function 'malloc' in function vGetPixelValueIntoArray(float *) Warning W8060 testpp.cpp 11: Possibly incorrect assignment in function vGetPixelValueIntoArray(float *) Error E2268 testpp.cpp 12: Call to undefined function 'fprintf' in function vGetPixelValueIntoArray(float *) Error E2451 testpp.cpp 12: Undefined symbol 'stderr' in function vGetPixelValueIntoArray(float *) Error E2268 testpp.cpp 13: Call to undefined function 'exit' in function vGetPixelValueIntoArray(float *) Warning W8057 testpp.cpp 16: Parameter 'pfImageData' is never used in function vGetPixelValueIntoArray(float *) Error E2268 testpp.cpp 23: Call to undefined function 'malloc' in function main(int,char * *) Error E2451 testpp.cpp 24: Undefined symbol 'stderr' in function main(int,char * *) Error E2268 testpp.cpp 24: Call to undefined function 'fprintf' in function main(int,char * *) Error E2451 testpp.cpp 25: Undefined symbol 'NULL' in function main(int,char * *) Error E2034 testpp.cpp 27: Cannot convert 'float * *' to 'float *' in function main(int,char * *) Error E2342 testpp.cpp 27: Type mismatch in parameter 'pfImageData' (wanted 'float *', got 'float * *') in function main(int,char * *) Error E2268 testpp.cpp 31: Call to undefined function 'free' in function main(int,char * *) Warning W8013 testpp.cpp 31: Possible use of 'ppfImageData' before definition in function main(int,char * *) Warning W8057 testpp.cpp 35: Parameter 'argc' is never used in function main(int,char * *) Warning W8057 testpp.cpp 35: Parameter 'argv' is never used in function main(int,char * *) *** 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
vGetPixelValueIntoArray(&ppfImageData[0]); //so mallocing the firstvGetPixelValueIntoArray(ppfImageData[0]); //so mallocing the first#include "stdio.h" #include "stdlib.h" #include "string.h" #include "ctype.h"
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h>
"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
•
•
Join Date: Jul 2005
Posts: 6
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Dave Sinkula
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 firstvGetPixelValueIntoArray(ppfImageData[0]); //so mallocing the first
•
•
•
•
[edit2]Why use so much C in a C++ source?
•
•
•
•
Originally Posted by Giant
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.••••Originally Posted by Dave SinkulaSince &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 firstvGetPixelValueIntoArray(ppfImageData[0]); //so mallocing the first
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 :/.
"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
•
•
Join Date: Jul 2005
Posts: 6
Reputation:
Solved Threads: 0
okay if I do just simply write surely I am only passing a value to the function, rather than the address of first pointer, which I need.
C Syntax (Toggle Plain Text)
ppfImageData[0]
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
![]() |
Similar Threads
- error C2664 (C++)
- error C2664: cannot convert parameter 1 from 'float (void)' to 'float' (Game Development)
- please fix the error (C++)
- Multithreading error (C++)
- Homework - error C2059: syntax error : ']' (C++)
- Help with Error message (C++)
- Delete words error!! (C++)
Other Threads in the C Forum
- Previous Thread: CW debugger stops at unwanted breakpoint
- Next Thread: i want help about the Simulate a Linux/UNIX shell, called MASH in the C
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






