comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison<dennison@telepath.com>
Subject: Re: How to convert record?
Date: Fri, 26 Oct 2001 20:02:10 GMT
Date: 2001-10-26T20:02:10+00:00	[thread overview]
Message-ID: <6jjC7.1904$xS6.2897@www.newsranger.com> (raw)
In-Reply-To: mghC7.32891$pb4.16100029@news2.rdc2.tx.home.com

In article <mghC7.32891$pb4.16100029@news2.rdc2.tx.home.com>, Smark says...
>
>"Ted Dennison" <dennison@telepath.com> wrote in message
>news:MreC7.1456$xS6.2002@www.newsranger.com...
>> In article <FE4C7.31012$pb4.15204037@news2.rdc2.tx.home.com>, Smark
>says...
>> >
>> >
>> >type Bubba_Type is record
>> >    C : Character; -- one byte
>> >    I   : Integer; -- 4 bytes
>> >end record;
>> >
>> >Bubba : Bubba_Type;
>> >
>> >Suppose that Integers must align on 4-byte boundaries.  Then you might
>> >get:
>> >
>> >Bubba_Type'Size = 40 (= 5 bytes)
>> >
>> >(Typename'size + System.Storage_Unit - 1) / System.Storage_Unit
>> >= ( 40 + 8 - 1)/8 = 47/8 = 6 (bytes)
>> >
>> >But actually:
>> >
>> >Bubba'Size = 64 (= 8 bytes)
>>
>> I do not believe that is the case. If objects of this type are going to
>> have holes in the middle for alignment purposes, then that should be 
>> reflected in the type's size.
>>
>
>Try it out, or check out what the GNAT reference manual has to say about
>GNAT's 'Object_Size attribute 

I did. I'm right. With Gnat on Win32, both Bubba_Type'size and Bubba'size are
64.

The example in the UG has the fields reversed from your example. I'll give you
that it does say that the type's 'size might be more than 7 bits smaller than
the object's 'size. However, it does *not* say that it would return some kind of
"packed" size for a type, where holes in the *middle* of a record are ignored,
as you seem to be implying. I do not believe an Ada compiler is allowed to do
this.

>(don't you suppose there is a reason that GNAT added this attribute?).

I thought it was so that you didn't have to have an object hanging around to
take a 'size on to get an exact size. As a matter of fact, I still think that.
:-)

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



  reply	other threads:[~2001-10-26 20:02 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-21  9:56 How to convert record? Joseph Kwan
2001-10-22 11:30 ` John McCabe
2001-10-25 11:40   ` Joseph Kwan
2001-10-25 12:38     ` sk
2001-10-25 17:12       ` Jeffrey L. Susanj
2001-10-25 12:48     ` David C. Hoos
2001-10-29  1:42       ` Joseph Kwan
2001-10-29 13:35         ` Marc A. Criley
2001-10-25 12:48     ` Marc A. Criley
2001-10-25 12:54       ` sk
2001-10-25 15:41         ` Ted Dennison
2001-10-26  3:21           ` Smark
2001-10-26  5:45             ` James Rogers
2001-10-26 17:46               ` Smark
2001-10-26 14:30             ` Ted Dennison
2001-10-26 17:42               ` Smark
2001-10-26 20:02                 ` Ted Dennison [this message]
2001-10-26 23:10             ` Jeffrey Carter
  -- strict thread matches above, loose matches on Subject: below --
2001-10-29 18:16 Beard, Frank
2001-10-30  1:17 ` Adrian Hoe
2001-10-30 19:05 Beard, Frank
2001-10-31  4:10 ` Adrian Hoe
2001-10-31 19:40 Beard, Frank
2001-11-01  2:13 ` Adrian Hoe
replies disabled

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