char *yn; yn = (char *) malloc (sizeof (char) * x * y); First subroutine included with {}: char (*pointer)[x][y] = (char (*)[x][y]) yn; &((*pointer)[0][0]) is 0x8052100 &((*pointer)[0][1]) is 0x8052107 Second routine independent function passed as pointer yn as parameter; char (*pointer)[x][y] = (char (*)[x][y]) yn; In second routine the pointers only is the same if (x) y replaced with (y) and (y) with (x) &((*pointer)[0][0]) with pointer 0x8052100 &((*pointer)[1][0]) with pointer 0x8052107
Can you provide a self contained example which actually compiles? As right now I (and others) can only guess at what the problem is.
Created attachment 11320 [details] test_code OUTPUT: ./gcc_test Printing matrix... 0x804a008 MATRIX [0][0] = [1] with pointer 0x804a008 MATRIX [0][1] = [2] with pointer 0x804a00f MATRIX [0][2] = [3] with pointer 0x804a016 MATRIX [0][3] = [4] with pointer 0x804a01d MATRIX [0][4] = [5] with pointer 0x804a024 MATRIX [0][5] = [6] with pointer 0x804a02b MATRIX [0][6] = [7] with pointer 0x804a032 create call... MATRIX [0][0]=[1] with pointer 0x804a008 MATRIX [0][1]=[0] with pointer 0x804a009 MATRIX [0][2]=[0] with pointer 0x804a00a MATRIX [0][3]=[0] with pointer 0x804a00b MATRIX [0][4]=[0] with pointer 0x804a00c MATRIX [0][5]=[0] with pointer 0x804a00d MATRIX [0][6]=[0] with pointer 0x804a00e Inverse order MATRIX [0][0]=[1] with pointer 0x804a008 MATRIX [1][0]=[2] with pointer 0x804a00f MATRIX [2][0]=[3] with pointer 0x804a016 MATRIX [3][0]=[4] with pointer 0x804a01d MATRIX [4][0]=[5] with pointer 0x804a024 MATRIX [5][0]=[6] with pointer 0x804a02b MATRIX [6][0]=[7] with pointer 0x804a032 OK
*(pointer_yn)[0][6] is different from: (*pointer_yn)[0][6] In fact the first one is equivalant to: pointer_yn[0][6][0] While the second one is equivalant to: pointer_yn[0][0][6] so you are running into different ordering of array references.