From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,79db4ff72bff9422 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-10-25 20:21:09 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!news2.rdc2.tx.home.com.POSTED!not-for-mail From: "Smark" Newsgroups: comp.lang.ada References: <80d2e34.0110210156.7918cd3d@posting.google.com> <3bd402f9.8783319@news.demon.co.uk> <80d2e34.0110250340.155ae0b7@posting.google.com> <3BD7FE89.53BF8436@earthlink.net> <%oWB7.96$xS6.155@www.newsranger.com> Subject: Re: How to convert record? X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 Message-ID: Date: Fri, 26 Oct 2001 03:21:09 GMT NNTP-Posting-Host: 24.254.173.165 X-Complaints-To: abuse@home.net X-Trace: news2.rdc2.tx.home.com 1004066469 24.254.173.165 (Thu, 25 Oct 2001 20:21:09 PDT) NNTP-Posting-Date: Thu, 25 Oct 2001 20:21:09 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:15207 Date: 2001-10-26T03:21:09+00:00 List-Id: "Ted Dennison" wrote in message news:%oWB7.96$xS6.155@www.newsranger.com... > In article , sk says... > > > >-- ... Use 'Size on a _variable_ of that type, not the type itself, > >-- and divide by System.Storage_Unit (i.e., 8). ... > > > >Why variable and NOT type ? > > Because the type will return the number of bits it could theoreticly fit into, > not the number it takes up. Thus you could get a result that isn't evenly > divisible by your storage unit (usually 8). > > Personally, I prefer to just adjust for that, rather than worry about it. > > (Typename'size + System.Storage_Unit - 1) / System.Storage_Unit > Well, would you worry about it with a type like this: 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) GNAT provides a nice attribute 'Object_Size that can be used on the type to give you what the size of an object of that type would be. Markku Kotiaho