delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/23/09:34:56

From: lonniem AT cs DOT utexas DOT edu (Lonnie McCullough)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Can't print address using cout
Date: Fri, 23 May 1997 05:49:01 GMT
Message-ID: <33852bf6.2512633@news.nol.net>
References: <337F611D DOT 4FCE AT netvision DOT net DOT il> <3380C376 DOT 6F173422 AT alcyone DOT com> <864340913 DOT 7033 AT dejanews DOT com>
NNTP-Posting-Host: ip38-36.nol.net
Lines: 43
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Thu, 22 May 1997 17:52:02 -0600, lenny AT netvision DOT net DOT il wrote:

>Erik,
>
>Thanks for your help.  The cast (void *) did the trick.
>
>However, isn't it strange that the djgpp compiler lacks such a basic
>function that would give it the ability to print out memory addresses
>(i.e. no member function ostream::operator <<(long *))?

Actually no it's not djgpp.  The iostream is an ANSI/ISO standard and
djgpp tries to stay as close to the standard as possible (as all "gnu"
products do).  Any compiler supporting a ostream::operator << (long *)
is strctly speaking not ANSI compatible.  Besides why should it have
to support all the different pointer types.  Consider this:

struct point
{
  int x;
  int y;
}

...
cout << &pointvar;

  If you wanted to print the address of this structure you would have
to overload the << operator to work with point*.  This doesn't make
any sense because an address is an address no matter what it is
pointing to.  So why not just overload the generic void* and type cast
any other pointers to void*.  Makes alot of sense to me.  You don't
want to have to overload for every pointer type you may ever encounter
do you?

And you can print out an address with printf (...).  Do it like this:

printf ("%p", &number);

or any type.  It is taken to be implicitly void here sorta.



Lonnie McCullough
lonniem AT cs DOT utexas DOT edu

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019