From 3574416490717901329
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,9684813612e15361
X-Google-Attributes: gidf78e5,public
From: James Kuyper <kuyper@wizard.net>
Subject: Re: pointers: sizeof(pointer)
Date: 1998/06/23
Message-ID: <358E8276.446B@wizard.net>#1/1
X-Deja-AN: 365198225
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
Content-Transfer-Encoding: 7bit
References: <slrn6oqcgp.lfi.sbnaran@bardeen.ceg.uiuc.edu>
X-Original-Date: Mon, 22 Jun 1998 12:12:38 -0400
Content-Type: text/plain; charset=us-ascii
Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANY8r5OEDnX0m9pzZAQHqagF/TTTS+yheI20jzMmShiKucDXbbL2w9XiJ mlTo49YIuufjFXQCMJQH2HKC/lbQUk+g =hX0x
Mime-Version: 1.0
Newsgroups: comp.std.c++


Tony Cook has already answered most of this; I'll just add a few more
points.

Siemel Naran wrote:
> 
> (1)
> 
> [X] Do all pointers have the same size?  This
> makes sense because a pointer of any type is
> just a memory addresss.

It need not be just a memory address. If an implementation chooses to
implement run-time array bounds checking, the necessary information may
be included in the pointer. There are also a lot of different virtual
memory schemes out there, some of which require complicated pointers.

> [X] But what about inheritance where one pointer
> can really be two pointers?  For example, if
> class D derives from class B, the a pointer to
> a B can also possibly be a pointer to a D.

It can be, but it needn't be. Casts within a class hierarchy can be
highly non-trivial.
 
> [X] The business of casting is just a compile
> time check on the correctness of our code.
> Correct?

No. Among other things, casting a pointer to a new type will generally
include changing its value, as needed, to match the alignment
restrictions of the new type.

> (2) Can we assume that sizeof(pointer)=sizeof(int)?

No. In fact, there is no guarantee than any integer type is large enough
to store a pointer; not even unsigned long.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



