From: "Nick Roberts" <nick.roberts@acm.org>
Subject: Re: Zero length Objects
Date: Thu, 1 Jul 2004 15:52:29 +0100
Date: 2004-07-01T15:52:29+01:00 [thread overview]
Message-ID: <2kimpdF2orakU1@uni-berlin.de> (raw)
In-Reply-To: 2oUEc.2$S77.1@nwrdny03.gnilink.net
"Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net> wrote in message
news:2oUEc.2$S77.1@nwrdny03.gnilink.net...
> "Brian May" <bam@snoopy.apana.org.au> wrote in message
> news:sa41xjwy2nv.fsf@snoopy.apana.org.au...
> > Is there any reason every object needs to have a unique address?
> The issue is that if A and B share an address, then they are basically
> aliases of each other, for no subprogram could distinguish between
> them. The programmer, however, is declaring A and B as two
> separate objects, so making them aliases would be a violation of the
> author's intentions.
I understand that the C and C++ standards mandate that all types (classes)
must have a size greater than zero, for the reasons Frank gave. To expand on
on his example a little, supposing we wrote a general-purpose termplate
function which had to make sure its two parameters were not aliased:
template <class C>
function wibble(C* x, C* y) {
if (x==y) raise Aliasing_Error;
...
};
if we then had a class with no members:
class CEmpty {
...
};
CEmpty a, b;
and tried to execute:
wibble(&a,&b);
we would wrongly get Aliasing_Error raised if a and b had been allocated to
the same address. The rule that types (and so their objects) cannot be of
zero size prevents this happening.
To my mind, a significant problem remains. If we declared something like:
CWhatever mem_a[1000000];
somewhere in a template class, where CWhatever was a template parameter, and
then instantiated the class with CEmpty replacing CWhatever, we would get a
mem_a in the instance that took up a whopping amount of memory to store
absolutely nada! Yuk.
PS: Please forgive any minor mistakes, I'm not a C++ expert.
--
Nick Roberts
next prev parent reply other threads:[~2004-07-01 14:52 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-30 5:55 Zero length Objects Robert C. Leif
2004-06-30 20:32 ` Jacob Sparre Andersen
2004-06-30 21:01 ` Frank J. Lhota
2004-07-01 0:02 ` Nick Roberts
2004-07-01 1:28 ` Georg Bauhaus
2004-07-01 10:37 ` Björn Persson
2004-07-01 11:25 ` Larry Kilgallen
2004-07-01 14:11 ` Nick Roberts
2004-07-01 15:42 ` Larry Kilgallen
2004-07-01 14:06 ` Xenos
2004-07-01 15:26 ` Nick Roberts
2004-07-02 1:06 ` Jeffrey Carter
2004-07-01 0:47 ` Brian May
2004-07-01 13:32 ` Frank J. Lhota
2004-07-01 14:52 ` Nick Roberts [this message]
2004-07-01 15:03 ` Xenos
2004-07-01 15:57 ` Hyman Rosen
2004-07-01 16:05 ` Xenos
2004-07-02 15:02 ` Frank J. Lhota
2004-07-02 15:11 ` Adrian Knoth
2004-07-02 15:43 ` Frank J. Lhota
2004-07-02 19:01 ` Vinzent 'Gadget' Hoefler
2004-07-02 19:07 ` Adrian Knoth
2004-07-02 19:25 ` Vinzent 'Gadget' Hoefler
2004-07-02 21:06 ` Xenos
2004-07-02 21:56 ` Vinzent 'Gadget' Hoefler
-- strict thread matches above, loose matches on Subject: below --
2004-07-02 8:30 Christoph Karl Walter Grein
2004-07-06 11:59 ` Nick Roberts
2004-07-06 22:14 ` Randy Brukardt
2004-07-06 22:28 ` Nick Roberts
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox