Bug 27272 - Strange order of components of multidimensional array pointer with the same cast
Summary: Strange order of components of multidimensional array pointer with the same cast
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-23 16:32 UTC by Fran
Modified: 2006-04-23 20:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
test_code (639 bytes, text/plain)
2006-04-23 20:20 UTC, Fran
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Fran 2006-04-23 16:32:05 UTC
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
Comment 1 Andrew Pinski 2006-04-23 17:46:20 UTC
Can you provide a self contained example which actually compiles?  As right now I (and others) can only guess at what the problem is.
Comment 2 Fran 2006-04-23 20:20:55 UTC
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
Comment 3 Andrew Pinski 2006-04-23 20:49:10 UTC
*(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.