Article View: comp.std.c++
Article #1362Re: pointer comparisons
From: Scott Turner
Date: Mon, 25 Jan 1993 15:15
Date: Mon, 25 Jan 1993 15:15
26 lines
1698 bytes
1698 bytes
In article <1993Jan20.173927.3061@vedge.com>, hendrik@vedge.com (Hendrik Boom) writes:
> In article <1993Jan11.190959.5305@lpi.liant.com>, pkt@lpi.liant.com (Scott Turner) writes:
> > If we have objects of a type which requires no state, e.g.
> > struct B{} a, b;
> > then in order for them to have distinct identities an implementation
> > might allocate addresses that don't point to valid memory. Again, no
> > storage is required.
>
> But if nonempty class C inherits from B, you have trouble comparing
> pointers to B with pointers to C that have been converted to B,
> unless you are careful that addresses of B's are outside of usable
> memory.
The trouble is negligible almost all of the time. For example,
struct C : B { int i; };
an implementation could convert "pointer to C" to "pointer to B" using the
same representation for both values. If some pointers to B are pointing to
invalid memory, the comparison will work out just right.
In unusual cases such as Johan Bengtsson's example, the compiler can "waste"
a byte for the base class.
--
Prescott K. Turner, Jr.
Liant Software Corp. (developers of LPI languages)
959 Concord St., Framingham, MA 01701 USA (508) 872-8700
UUCP: uunet!lpi!pkt Internet: pkt@lpi.liant.com
Technical Details
Message-ID:
<1993Jan25.151516.24326@lpi.liant.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!titan!lpi!pktReferences:
<1993Jan18.182452.15390@lpi.liant.com> <1993Jan20.173927.3061@vedge.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!titan!lpi!pkt From: pkt@lpi.liant.com (Scott Turner) Subject: Re: pointer comparisons Message-ID: <1993Jan25.151516.24326@lpi.liant.com> Sender: pkt@lpi (Scott Turner) Organization: Liant Software Corporation References: <1993Jan18.182452.15390@lpi.liant.com> <1993Jan20.173927.3061@vedge.com> Date: Mon, 25 Jan 1993 15:15:16 GMT Lines: 26