Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: "aalfonso" , djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: Address of Operator Date: Fri, 1 May 1998 22:10:15 -0700 Message-ID: <19980502051013.AAA531@ppp122.cartsys.com> Precedence: bulk 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