comp.lang.ada
 help / color / mirror / Atom feed
From: "Peter C. Chapin" <chapinp@acm.org>
Subject: Re: Question about package Interfaces.
Date: Mon, 13 Sep 2010 14:31:56 -0400
Date: 2010-09-13T14:31:56-04:00	[thread overview]
Message-ID: <4c8e6e94$0$2400$4d3efbfe@news.sover.net> (raw)
In-Reply-To: <wccbp81d90n.fsf@shell01.TheWorld.com>

On 2010-09-13 10:15, Robert A Duff wrote:

> You can say "for A'Component_Size use 8;".  For records,
> you can specify the size of each component.  For standalone
> objects, you can specify 'Size.
> 
> But my point was just that the 'Size of an object
> is not guaranteed to be the same as the 'Size of
> its subtype.

Okay I think I'm understanding. So for example:

declare
   type Byte is mod 2**8;
   for Byte'Size use 8; -- The subtype has this size.

   X : Byte;            -- Could be more than 8 bits.
   for X'Size use 8;    -- Except no.. must be 8 bits (is this legal).

   type Byte_Array is array(Natural range <>) of Byte;
   for Byte_Array'Component_Size use 8;
                        -- Each array component is 8 bits.
begin
   null;
end;

When you say "object" I understand you to mean the in-memory
representation of an entity.

> You might want to look into the GNAT-specific
> 'Object_Size attribute.

I looked it up, thanks. It was helpful. So I see that at least one issue
is related to alignment. So in the Byte_Array declaration above, without
the Component_Size declaration the compiler could use, say, 16 bits for
each component to force word (2 byte) alignment on the components if it
thought there was some advantage in doing so. However, with the
Component_Size declaration the compiler must pack the components (since
all 8 bits are needed for the representation).

Does that sound right?

Peter



  reply	other threads:[~2010-09-13 18:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-13  1:10 Question about package Interfaces Peter C. Chapin
2010-09-13  3:54 ` Robert A Duff
2010-09-13 13:47   ` Peter C. Chapin
2010-09-13 14:15     ` Robert A Duff
2010-09-13 18:31       ` Peter C. Chapin [this message]
2010-09-13 22:47         ` Robert A Duff
2010-09-14  6:33     ` J-P. Rosen
2010-09-14 16:36       ` Jeffrey Carter
2010-09-14 17:01         ` J-P. Rosen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox