This is the mail archive of the gcc@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]

C++ bug (references)


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/
--


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