This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/11751] wrong evaluation order of an expression
- From: "d_picco at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Feb 2005 20:46:35 -0000
- Subject: [Bug c/11751] wrong evaluation order of an expression
- References: <20030731175202.11751.me@elitsa.net>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From d_picco at hotmail dot com 2005-02-23 20:46 -------
Here is a better clarification:
Case 1
======
int a = 0;
int b = a++ + a++;
printf("b = %d\n", b); // output is 0
Case 2
======
class A
{
int a_;
public:
A() : a_(0) {}
int operator++() { return a_++; }
};
A a;
int b = a++ + a++;
printf("b = %d\n", b); // output is 1
This is a simple case that shows how the behaviour of the operator++ should be
united.
I'm not sure what you mean by the system(...) call... I understand that the code
is undefined (meaning its up to the compiler vendor to implement as they see
fit). I think the most fitting way is to have the above two cases unified in
behaviour... isn't one of the reasons that operators were added to C++ was to
allow user-defined types to mimic the functionality and usability of the native
C types?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11751