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,38ceb882eed41e1e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-10-10 23:24:27 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: byhoe@greenlime.com (Adrian Hoe) Newsgroups: comp.lang.ada Subject: Re: Size and pack Date: 10 Oct 2001 23:24:27 -0700 Organization: http://groups.google.com/ Message-ID: <9ff447f2.0110102224.5c470e2c@posting.google.com> References: <9ff447f2.0110100005.2503bb00@posting.google.com> NNTP-Posting-Host: 210.186.172.215 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1002781467 22686 127.0.0.1 (11 Oct 2001 06:24:27 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 11 Oct 2001 06:24:27 GMT Xref: archiver1.google.com comp.lang.ada:14216 Date: 2001-10-11T06:24:27+00:00 List-Id: lutz@iks-jena.de (Lutz Donnerhacke) wrote in message news:... > * Adrian Hoe wrote: > >I have the following declaration: > > type Rx_Header_Data is > > record > > Start_Byte : Character := Latin_1.STX; > > Splitter : Character; > > Command_Byte : Character; > > Pad_Byte_1 : Character; > > Pad_Byte_2 : Character; > > Five Bytes so far. > > > Log_Num : Interfaces.C.Long; > > End_Byte : Character := Latin_1.ETX; > > LRC : Character; > > end record; > > > >It supposed to be 11 bytes long but Rx_Header_Data'Size reports 14 > >bytes. 'Size will report 11 bytes when I add the following line: > > > >pragma pack (Rx_Header_Data); > > > >I have found that Log_Num : Interfaces.C.Long takes up 7 bytes without > >pragma pack. > > As expected. > > >Why this happens? > > Log_Num is aligned to use a single 64bit RAM access instead of bursting two > 32bit accesses. Pragma Pack favors size over speed. > > >Can I use representation clause instead of pragma pack? > > Yes. > > >If both methods work, which is the best approach and why? > > Depends on your needs: > - If you only need the small size, let the compiler choose the > representation. (-gnatR shows the compilers decision) > for rx_header_data_packed use record > start_byte at 0 range 0 .. 7; > splitter at 1 range 0 .. 7; > command_byte at 2 range 0 .. 7; > pad_byte_1 at 3 range 0 .. 7; > log_num at 4 range 0 .. 31; -- Changed > pad_byte_2 at 8 range 0 .. 7; -- Changed > end_byte at 9 range 0 .. 7; > lrc at 10 range 0 .. 7; > end record; > - If you need a special layout (i.e. for interfacing), > use record representation clauses. The record structure will be used to interface with COTS product which sends out data in specific byte orders. The shuffle is not viable in this case. This will be intended on 32-bit Intel. What will be the effect if I use representation clauses on 64-bit processor? Adrian