I have the following versions of passing 2D array as pointer.
Version 1
#include <stdio.h>
void disp(int a[][5])
{
printf("a[0][3] = %d\n", a[0][3]); /* a[0][3] = 4 */
}
int main ()
{
int a[10] = {1,2,3,4,5,6,7,8,9,10};
disp(a);
return 0;
}
Version 2
#include <stdio.h>
typedef void(*callDisplay)(int*);
void disp(int a[][5])
{
printf("a[0][3] = %d\n", a[0][3]); /* a[0][3] = 4 */
}
int main ()
{
int a[10] = {1,2,3,4,5,6,7,8,9,10};
callDisplay fn = (callDisplay) &disp;
fn(a);
return 0;
}
Version 1 rises warning incompatible pointer type. expected int (*)[5] but argument is of type int * as expected. However, (Version 2) calling the same function with pointer is compiling without any such warnings.
gcc options: gcc -O0 -g3 -Wall -c -fmessage-length=0
Could somebody pass light on this?