This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/15103] New: postincrement precedence lower than assignment
- From: "musicman529 at yahoo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Apr 2004 18:13:38 -0000
- Subject: [Bug c/15103] New: postincrement precedence lower than assignment
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
In the following program:
==========================================
#include <stdio.h>
int main(int argc, char *argv[]) {
int x = 20, y = 35;
x = x++ + y++;
y = ++x + ++y;
printf("x=%d y=%d\n", x, y);
return 0;
}
==========================================
In the first assignment line "x = x++ + y++;", the code emitted by the i386
compiler processes the post-increment operators after the assignment, so that
the addition result gets incremented in "x".
1. Shouldn't "x++" be semantically equivalent to "(x += 1, x - 1)"? The first
assignment produced assembly that behaved more like:
x = x + y;
x++;
y++;
I tried to use parentheses around the increment expressions to force the
precedence, but they were ignored.
2. Don't the increment and decrement operators have a much higher precedence
than assignment?
I'll admit, any coder working for me who wrote code like the above, would be
fired on the spot. This is a very small corner case. However, it may point to a
larger issue that needs to be resolved, so I'm filing it "just in case".
--
Summary: postincrement precedence lower than assignment
Product: gcc
Version: 3.3.3
Status: UNCONFIRMED
Severity: minor
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: musicman529 at yahoo dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: i486-slackware-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15103