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=-0.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM, FREEMAIL_REPLYTO_END_DIGIT,REPLYTO_WITHOUT_TO_CC autolearn=no 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:07:07 PST From: Pi Subject: Re: Size and pack Newsgroups: comp.lang.ada Reply-To: pi3_1415926536@yahoo.ca References: <9ff447f2.0110100005.2503bb00@posting.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8Bit User-Agent: KNode/0.3.2 Message-ID: Date: Wed, 10 Oct 2001 05:24:34 -0400 NNTP-Posting-Host: 65.94.128.181 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1002704351 65.94.128.181 (Wed, 10 Oct 2001 04:59:11 EDT) NNTP-Posting-Date: Wed, 10 Oct 2001 04:59:11 EDT Organization: Bell Sympatico Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!newsswitch.lcs.mit.edu!sunqbc.risq.qc.ca!torn!webster!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail Xref: archiver1.google.com comp.lang.ada:14127 Date: 2001-10-10T05:24:34-04:00 List-Id: Adrian Hoe wrote : > Hello, > > I have the following declaration: > > type Rx_Header_Data is > record > Start_Byte : Character := Latin_1.STX; 1st byte > Splitter : Character; 2nd byte > Command_Byte : Character; 3rd byte > Pad_Byte_1 : Character; 4th byte > Pad_Byte_2 : Character; 5th byte 3 bytes space to align with a memory word (32 bit) > Log_Num : Interfaces.C.Long; 8th - 12th byte > End_Byte : Character := Latin_1.ETX; 13th byte > LRC : Character; 14th byte > 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. > > Why this happens? Can I use representation clause instead of pragma > pack? If both methods work, which is the best approach and why? > > I use GNAT 3.13p on Linux. > > Thank you. It's much faster to access variables that are on full word-frontiers, so GNAT adds a 3 bytes "hole" into your record. Try this definition instead : type Rx_Header_Data is record Log_Num : Interfaces.C.Long; <-------1st position Start_Byte : Character := Latin_1.STX; Splitter : Character; Command_Byte : Character; Pad_Byte_1 : Character; Pad_Byte_2 : Character; End_Byte : Character := Latin_1.ETX; LRC : Character; end record; Yes I know it's silly to simply shuffle the definitions, but it should work. Also try to compile with full optimization (-O3) and GNAT may find the shuffle himself (not sure about this) If, for some reasons, you cant shuffle the definitions, you have to use Pack. If you can, shuffle, as Pack makes your memory access slighly slower. -- 3,14159265359