Article View: comp.unix.programmer
Article #3443Re: Displaying addresses of variables in hex?
From: Dietmar Kuehl
Date: Sun, 17 Nov 1996 00:00
Date: Sun, 17 Nov 1996 00:00
32 lines
1777 bytes
1777 bytes
Hi,
Borg (vladimip@iceonline.com*) wrote:
: How do I display variable addresses in hex rather than in decimal?
: An example:
: double var;
: cout << "var value is " << var << " and its address is ";
: cout << unsigned (&var) << endl;
I'm not sure whether it is standard conforming to do a conversion from
some pointer to an 'unsigned' (IMO it should not) but given that it
works, you can use the 'hex' manipulator, i.e.
cout << hex << unsigned (&var) << endl;
However, the correct way to print a pointer is like this:
cout << &var << endl;
: My (platform/OS independent) books insist on using:
: cout << &var << endl; (without "unsigned" and without
: round brackets!) I am using gcc/g++ 2.7.2 on Linux-i586.
And, guess what, they are correct! Every pointer is convertible to
'void const *' and there is an inserter for exactly this type which
prints the address in an implementation defined way, normally in hex.
--
<mailto:dietmar.kuehl@uni-konstanz.de>
<http://www.informatik.uni-konstanz.de/~kuehl/>
I am a realistic optimist - that's why I appear to be slightly pessimistic
Technical Details
Message-ID:
<56mhus$ruc$1@news.belwue.de>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<56m5ch$noi@news.iceonline.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc89c,7ec25c815d4734dc X-Google-Attributes: gidfc89c,public X-Google-Thread: 10ba33,7ec25c815d4734dc X-Google-Attributes: gid10ba33,public From: kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl) Subject: Re: Displaying addresses of variables in hex? Date: 1996/11/17 Message-ID: <56mhus$ruc$1@news.belwue.de> X-Deja-AN: 197001018 references: <56m5ch$noi@news.iceonline.com> followup-to: comp.unix.programmer,gnu.g++.help organization: Fakult�t f�r Mathematik und Informatik reply-to: dietmar.kuehl@uni-konstanz.de newsgroups: comp.unix.programmer,gnu.g++.help