In vc 6.0:
#include <iostream>
using namespace std;
int main()
{
int a = 10;
int b = 20;
a = (a + b) - (b = a);
cout << "a=" << a << ",b=" << b << endl;
return 0;
}
Release output : a=20,b=10
Debug output: a=10,b=10
why?
As has been pointed out, this is comp.lang.c, not comp.lang.c++.
However, noting that this is a C answer, and may be 100% wrong for
a C++ program....
a = (a + b) - (b = a);
I believe that this invokes "undefined behavior", because you both
use and modify "b" between sequence points. There is no guarantee
that the "b" in "a+b" will be evaluated before the "b" in "b=a".
You may get the equivalent of:
a = (10 + 20) - (10);
or
a = (10 + 10) - (10);
or
system("format c:");
The fact that you get what appears to be the first behavior for
"release" and the second for "debug" is perfectly acceptable, as
"undefined behavior" means _anything_ can happen.
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody |
www.hvcomputer.com | |
| kenbrody/at\spamcop.net |
www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:
[email protected]>