chin@sg1.chem.upenn.edu (Chin Wu) (07/01/90)
Following codes behave differently in Turbo C++ and G++. I am not so sure is this difference due to different version of stream used in these two compilers or is it a bug in Turbo C++. ------------------- #include <stream.h> --> change to #include <iostream.h> in Turbo C++ int test(int& x) { x = 10; return 100; }; main() { int x = 200; cout << test(x) << '\n' << x << '\n'; }; --------------------- Turbo C++ output : 100 200 G++ output : 100 10 --------------------- -- chin@sg1.chem.upenn.edu
mike@taumet.com (Michael S. Ball) (07/01/90)
In article <CHIN.90Jul1025412@sg1.chem.upenn.edu> chin@sg1.chem.upenn.edu (Chin Wu) writes: >Following codes behave differently in Turbo C++ and G++. I am not so >sure is this difference due to different version of stream used in >these two compilers or is it a bug in Turbo C++. : : >Turbo C++ output : 100 > 200 >G++ output : 100 > 10 The result of the code depends on the order in which different parts of an expression are evaluated. That order is undefined, and code which depends on evaluation order is highly non-portable. We seem to go through this periodically in these newsgroups. I am tempted to say that all compilers should warn about these situations just to reduce traffic on usenet. (Ours doesn't, but I'm getting very tempted.....) Mike Ball TauMetric Corporation mike@taumet.com