Article View: gnu.g++.bug
Article #1042Re: new bug: (none)
From: David Kastrup
Date: Fri, 09 Oct 1992 18:29
Date: Fri, 09 Oct 1992 18:29
42 lines
2148 bytes
2148 bytes
werner@ast1.uibk.ac.at ( Werner Benger ) writes:
> There seems to be another bug in the GNU C++ 2.2.2 Compiler:
> If a constant reference is created, the value of the original variable
> is copied once to a different place where the reference points to.
> Therefore the reference value is not affected when the variable is changed.
> In the following example the output should be:
> 19 5 7 11 instead of 19 19 19 19
If you want to declare a constant pointer to an int, you have to
declare int & const y;
Although this is pretty pointless, because references cannot be
changed after initialization anyhow. But you decalred a reference
to a constant integer. Since you gave a non-constant integer as
an argument, C++ converted to a constant integer by making a copy.
This is perfectly legal. If you want a reference to the CHANGING
integer, declare it without const.
The other `error' is to be reported to a different list, I believe.
> The same error occurs when "int" is changed to "double".
> While debugging, I detected also an mistake ( is it a mistake ?)
> in <iostream.h> :
> ostream&operator<<(ostream&,void*)
> should be changed into
> ostream&operator<<(ostream&,const void*)
> since the content of a pointer been printed out is not changed
> ( at least it should not ). With the current version a warning message
> is produced when compiling the program below.
>#include <iostream.h>
>int x=19;
>main()
>{
>const int&y=x;
> cout << y << " ";
> x=5; cout << y << " ";
> x=7; cout << y << " ";
> x=11; cout << y << " ";
> cout << &x << " " << &y << '\n';
> return 0;
>}
Technical Details
Message-ID:
<dak.718655387@tabaqui>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!tabaqui.informatik.rwth-aachen.de!dakReferences:
<9210052005.AA08803@ast1.uibk.ac.at>Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!tabaqui.informatik.rwth-aachen.de!dak From: dak@tabaqui.informatik.rwth-aachen.de (David Kastrup) Subject: Re: new bug: (none) Message-ID: <dak.718655387@tabaqui> Sender: gnulists@ai.mit.edu Organization: Rechnerbetrieb Informatik / RWTH Aachen References: <9210052005.AA08803@ast1.uibk.ac.at> Distribution: gnu Date: Fri, 9 Oct 1992 18:29:47 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 49