public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/17253] New: Inconsistency in reading array indexes
@ 2004-08-31 19:50 vanveghel at home dot nl
2004-08-31 20:03 ` [Bug c/17253] " falk at debian dot org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: vanveghel at home dot nl @ 2004-08-31 19:50 UTC (permalink / raw)
To: gcc-bugs
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
--
Summary: Inconsistency in reading array indexes
Product: gcc
Version: 3.3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: vanveghel at home dot nl
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: 3.3.4
GCC host triplet: 3.3.4
GCC target triplet: 3.3.4
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17253
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/17253] Inconsistency in reading array indexes
2004-08-31 19:50 [Bug c/17253] New: Inconsistency in reading array indexes vanveghel at home dot nl
@ 2004-08-31 20:03 ` falk at debian dot org
2004-08-31 20:44 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: falk at debian dot org @ 2004-08-31 20:03 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From falk at debian dot org 2004-08-31 20:03 -------
Uhm, the code is invalid, and the compiler warns about it. What could possibly
be improved?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17253
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/17253] Inconsistency in reading array indexes
2004-08-31 19:50 [Bug c/17253] New: Inconsistency in reading array indexes vanveghel at home dot nl
2004-08-31 20:03 ` [Bug c/17253] " falk at debian dot org
@ 2004-08-31 20:44 ` pinskia at gcc dot gnu dot org
2004-08-31 20:46 ` bangerth at dealii dot org
2004-08-31 20:46 ` bangerth at dealii dot org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-31 20:44 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-08-31 20:44 -------
No there is nothing which can be improved except maybe for you fixing your code not be use undefined
code.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17253
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/17253] Inconsistency in reading array indexes
2004-08-31 19:50 [Bug c/17253] New: Inconsistency in reading array indexes vanveghel at home dot nl
` (2 preceding siblings ...)
2004-08-31 20:46 ` bangerth at dealii dot org
@ 2004-08-31 20:46 ` bangerth at dealii dot org
3 siblings, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2004-08-31 20:46 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-08-31 20:46 -------
Duplicate of PR 11751.
*** This bug has been marked as a duplicate of 11751 ***
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17253
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/17253] Inconsistency in reading array indexes
2004-08-31 19:50 [Bug c/17253] New: Inconsistency in reading array indexes vanveghel at home dot nl
2004-08-31 20:03 ` [Bug c/17253] " falk at debian dot org
2004-08-31 20:44 ` pinskia at gcc dot gnu dot org
@ 2004-08-31 20:46 ` bangerth at dealii dot org
2004-08-31 20:46 ` bangerth at dealii dot org
3 siblings, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2004-08-31 20:46 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-08-31 20:46 -------
Indeed. What more than a warning do you want?
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17253
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-08-31 20:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-31 19:50 [Bug c/17253] New: Inconsistency in reading array indexes vanveghel at home dot nl
2004-08-31 20:03 ` [Bug c/17253] " falk at debian dot org
2004-08-31 20:44 ` pinskia at gcc dot gnu dot org
2004-08-31 20:46 ` bangerth at dealii dot org
2004-08-31 20:46 ` bangerth at dealii dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).