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 02:27:10 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!cpk-news-hub1.bbnplanet.com!news.gtei.net!news-FFM2.ecrc.net!news.iks-jena.de!lutz From: lutz@iks-jena.de (Lutz Donnerhacke) Newsgroups: comp.lang.ada Subject: Re: Size and pack Date: Wed, 10 Oct 2001 09:27:08 +0000 (UTC) Organization: IKS GmbH Jena Message-ID: References: <9ff447f2.0110100005.2503bb00@posting.google.com> NNTP-Posting-Host: taranis.iks-jena.de X-Trace: branwen.iks-jena.de 1002706028 14368 217.17.192.37 (10 Oct 2001 09:27:08 GMT) X-Complaints-To: usenet@iks-jena.de NNTP-Posting-Date: Wed, 10 Oct 2001 09:27:08 +0000 (UTC) User-Agent: slrn/0.9.6.3 (Linux) Xref: archiver1.google.com comp.lang.ada:14128 Date: 2001-10-10T09:27:08+00:00 List-Id: * 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.