This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
C++ bug (references)
- To: egcs at egcs dot cygnus dot com
- Subject: C++ bug (references)
- From: Sam Lantinga <slouken at devolution dot com>
- Date: Fri, 26 Feb 1999 09:49:39 -0800
- Cc: slouken at devolution dot com, highlander at lokigames dot com
Using egcs 1.1.1 stock, the following code produces unexpected output:
#include <stdio.h>
func(int &val)
{
val = 3;
}
main()
{
int val = 0;
func((int)val);
printf("Val is %d\n", val);
}
---
The output is 0, where I would expect it to be 3, and under other compilers
(VC++) it is 3.
The warning during compile is:
t3.cc: In function `int main()':
t3.cc:13: warning: initialization of non-const reference `int &' from rvalue `int'
t3.cc:5: warning: in passing argument 1 of `func(int &)'
Why is it creating a temporary variable in the cast of int?
See ya!
-Sam Lantinga (slouken@devolution.com)
Lead Programmer, Loki Entertainment Software
--
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/
--