[Bug c++/11374] New: Call by reference using enum casted to int passes in wrong address
mike at mikesclutter dot com
gcc-bugzilla@gcc.gnu.org
Mon Jun 30 01:21:00 GMT 2003
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11374
Summary: Call by reference using enum casted to int passes in
wrong address
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mike at mikesclutter dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: ?
GCC host triplet: ?
GCC target triplet: ?
Platform: Linux 2.4.20 #3 Fri May 30 08:25:22 CDT 2003 i686 Intel(R)
Pentium(R) III Mobile CPU 1133MHz GenuineIntel GNU/Linux
Overview:
This problem did not occur in previous versions of gcc (on linux at least).
Basically, call by reference when using enum arguments (casted as int) does not
provide the correct reference to the called function.
A simple example:
// The enum
enum _t
{
off = 0,
on = 100
};
// The function
void fn(int& x)
{
// The rub: &x != &t in main(), although it should.
printf("&x in fn(): %x\n", &x);
x = on;
printf("value set in fn(): %i\n", x);
}
// The caller
void main()
{
_t t = off;
printf("&t in main(): %x\n", &t);
fn((int)t);
printf("value received in main(): %i\n", t);
}
This produces the following output:
&t in main(): bffff6d0
&x in fn(): bffff6cc
value set in fn(): 100
value received in main(): 0
Thus, since &t != &x, the variable t is never set to the proper value by fn()
even though it is called by reference.
More information about the Gcc-bugs
mailing list