>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.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
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 ***
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
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?
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
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:[indent]Since &ppfImageData[0] is the same as ppfImageData, which is a float**, and since vGetPixelValueIntoArray receives a float*[/indent]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.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
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;
}
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
If you tried to pass merely a float* you would be passing a copy of the pointer's address. Modifying the copy would not change the original.
In C if you want to change the value of an object passed to a function (by malloc'ing memory to it for example), you need to simulate pass-by-reference by passing a pointer to the object. If the object is itself a pointer, you will need to pass a pointer to a pointer.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314