Consider the following two snippets: -- snip snip -- #include <stdio.h> #include <string.h> int main (void) { char test[5][5]; int j = 3; memset (&test, ' ', 5 * 5); test[j][j++] = '!'; printf ("test[3][3] = %c\ntest[4][3] = %c\n", test[3][3], test[4][3]); return 0; } -- snip snip -- And: -- snip snip -- #include <stdio.h> #include <string.h> int main (void) { char test[5][5]; int j = 3; memset (&test, ' ', 5 * 5); test[(j == 4) ? 4 : 3][j++] = '!'; printf ("test[3][3] = %c\ntest[4][3] = %c\n", test[3][3], test[4][3]); return 0; } -- snip snip -- Running both these snippets produces the following results with GCC 3.3.4 running on Debian GNU/Linux Unstable (x86): $ ./test test[3][3] = test[4][3] = ! $ ./test2 test[3][3] = ! test[4][3] = $ It seems that j++ is evaluated first only in the second case, making the statement in the first bracket evaluate to 4. This may be a result of 'undefined behavior' caused by sequence points, and indeed, GCC does issue a warning ("warning: operation on `j' may be undefined"), but it does seem like something that can at least be improved. Kind Regards, Jasper
Uhm, the code is invalid, and the compiler warns about it. What could possibly be improved?
No there is nothing which can be improved except maybe for you fixing your code not be use undefined code.
Indeed. What more than a warning do you want?
Duplicate of PR 11751. *** This bug has been marked as a duplicate of 11751 ***