Hi folks, i want to know how can i pass an array wich has been created with malloc() as a param. I have tried out this:
First try:
With this way, it works fine. But i have a serious doubt. When i create my array, i'm determining that it will be a 10x6 matrix. But when i set as a param i'm determining that it will have 1x1 elements. So, what are the secondary effects that might appear with this code?Code://array declaration int (*myimage)[6]; myimage = (int (*)[6]) malloc ( sizeof (int) * 10 * 6 ); myimage[0][3] = 5; //function call readTIFFImageArray ( "" , 90 , 100 , myimage ); //test function declaration void readTIFFImageArray ( char *filename , unsigned long imageWidth , unsigned long imageHeight , int array[0][0] ) { printf ( "%i\n" , array[0][3] ); }
Second way:
If i write code like it's shown above, it throws the following error:Code://array declaration // ... same as first try //function call // ... same as first try //test function declaration and implementation void readTIFFImageArray ( char *filename , unsigned long imageWidth , unsigned long imageHeight , int array[][] ) { printf ( "%i\n" , array[0][3] ); }
invalid use of array with unspecified bounds.
So wich is the correct way of doing it?
Thanks in advance.



LinkBack URL
About LinkBacks



