http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57853
Bug ID: 57853 Summary: pointer arithmetic on arrays Product: gcc Version: 4.6.3 Status: UNCONFIRMED Severity: critical Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: brodhow at all2easy dot net This C code: #include <stdio.h> int main() { char *arr [2][3]={{"as","df","ce"},{"me","yu","we"}}; char *arr2 = NULL; puts(*arr[0]);//works fine puts(*arr[1]);//works fine printf("%c\n",*++arr[0][0]);//works fine and prints s printf("%s\n", *arr[0]); int i = 0, j = 0; for (i=0; i<2; ++i) for (j=0; j<3; ++j) printf("%s ", arr[i][j]); printf("\n"); } outputs: as me s s s df ce me yu we where the 'a' in "as" (arr[0]) is being wiped out! After the "printf("%c\n",*++arr[0][0]);" statement! Or, the string arr's head is being reassigned to the new value after the "*++arr[0][0]" operation which is 's'! the output should be: as me s as as df ce me yu we where the 'a' in "as" is present, afterwards! The pointer arithmetic here to get 's' to output is producing this side effect of wiping out the 'a' in "as", arr[0]. Is "*++arr[0][0]" valid for getting 's' in "as"? If so, then this side effect is happening! For real in any legacy C code with similar syntax! When said C code is recompiled by the current gcc compiler! Note that g++ does the same thing here too, on this code.