Mail Archives: djgpp/1998/05/02/01:16:09
At 08:49 4/30/1998 -0400, aalfonso wrote:
>I'm trying out a sample program in my C++ book. The program should print the
>memory address of a variable to the screen using the address of operator
>& . This is a sample;
>
>unsigned short int myAge = 5;
>cout << "myAge: " << myAge << "\n";
>cout << "&myAge: " << &myAge << "\n";
>
>this should output:
>myAge: 5
>&myAge: 0x355C // or some such address
>
>I always get this output when I use the & operator in this context.
>
>myAge: 5
>&myAge: 1
>
>Could someone tell me if i'm doing something wrong? Or does Djgpp not
>support the & operator in this context? Any help is greatly appreciated.
No, you're not doing anything wrong. This is a known bug in the C++ library.
I believe it is fixed in the 2.8.0 compiler/library package, so you could
upgrade to that and see if it goes away. Alternatively, as a workaround,
cast the value to `unsigned long', and do whatever C++ magic makes it print
in hex (as you can tell, I don't use C++ much :)
Nate Eldredge
nate AT cartsys DOT com
- Raw text -