This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: c++/2673


The following reply was made to PR c++/2673; it has been noted by GNATS.

From: "Uwe F. Mayer" <mayer@tux.org>
To: <gcc-gnats@gcc.gnu.org>
Cc: <pme@gcc.gnu.org>
Subject: Re: c++/2673
Date: Sun, 29 Apr 2001 11:42:42 -0400 (EDT)

 I am withdrawing my bug report with Synopsis: c++ calls by value instead
 of by reference. It is not a bug but bad code. In the example code the
 call is actually made as a call-by-reference, it just happens that I am
 using "d" twice in the same statement, and the compiler can evaluate the
 pieces of the statement any way it seems fit. In this case "d" gets
 evaluated before the side-effect of the call to "f" occurs. This is
 similar to the old textbook example of not using j=++i+i, where the
 results are system dependent.
 
 #include <iostream>
 using namespace std;
 
 double f(double& x)
 { x=1; return 2; }
 
 int main() {
    double d=5;
    // bad code: the line below produces false output of "2    5"
    cout << f(d) << "\t" << d << endl;
    // the line below produces correct output of "2    1"
    cout << f(d); cout << "\t" << d << endl;
 }
 
 
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]