This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/2674: c++ calls by value instead of by reference
- To: <gcc-gnats at gcc dot gnu dot org>
- Subject: c++/2674: c++ calls by value instead of by reference
- From: "Uwe F. Mayer" <mayer at tux dot org>
- Date: Fri, 27 Apr 2001 23:35:57 -0400 (EDT)
>Number: 2674
>Category: c++
>Synopsis: c++ calls by value instead of by reference
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Fri Apr 27 20:46:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Uwe F. Mayer
>Release: 3.0 20010409 (prerelease)
>Organization:
tux.org
>Environment:
System: Linux tosca 2.2.18 #2 Thu Mar 8 13:48:25 PST 2001 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --prefix=/usr/local/gcc --disable-nls
>Description:
When calling a function with a call-by-reference inside a printing
statement the variable does not get updated, effectively calling as
a call-by-value.
>How-To-Repeat:
Compile and run this program:
#include <iostream>
using namespace std;
double f(double& x)
{
x=1;
return 2;
}
int main()
{
double d=5;
cout << f(d) << "\t" << d << endl;
// the line below produces correct output of "2 1"
// double y=f(d); cout << y << "\t" << d << endl;
}
On my system it outputs:
2 5
instead of the correct:
2 1
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: