comp.lang.ada
 help / color / mirror / Atom feed
From: "Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net>
Subject: Re: Zero length Objects
Date: Thu, 01 Jul 2004 13:32:46 GMT
Date: 2004-07-01T13:32:46+00:00	[thread overview]
Message-ID: <2oUEc.2$S77.1@nwrdny03.gnilink.net> (raw)
In-Reply-To: sa41xjwy2nv.fsf@snoopy.apana.org.au

"Brian May" <bam@snoopy.apana.org.au> wrote in message
news:sa41xjwy2nv.fsf@snoopy.apana.org.au...
> >>>>> "Frank" == Frank J Lhota <NOSPAM.lhota.adarose@verizon.net> writes:
>
>     Frank> No object is really of zero length. The reason is that
>     Frank> every object should have a unique address. Therefore, most
>     Frank> Ada compilers will allocate at least one storage element to
>     Frank> each object, in order to insure that if we declare
>
>     Frank> A, B : Empty_Type;
>
>     Frank> then A and B do not both refer to the same location.
>
> 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.

AFAIK C++ takes the same approach. In fact, the first C++ tutorial I went
through (the one that came with Borland's groundbreaking BC++ compiler for
DOS and Windows) included a code sample that was something like this:

    class CEmpty {};
    ...
    CEmpty a, b;

The tutorial recommended generating an assembly listing for this code to
note that even though CEmpty is empty, a and b are allocated at separate
addresses, and that this is important because operations should be able to
distinguish a and b. I tried this with GCC and MSVC. Not only did both
compilers assign a and b separate addresses, but for both of these compilers

    ( sizeof( CEmpty ) == 1 ) && ( sizeof( a ) == 1 )





  reply	other threads:[~2004-07-01 13:32 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 [this message]
2004-07-01 14:52       ` Nick Roberts
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