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-25 21:00:40 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: <9ff447f2.0110100005.2503bb00@posting.google.com> Subject: Re: Size and pack 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 04:00:40 GMT NNTP-Posting-Host: 24.254.173.165 X-Complaints-To: abuse@home.net X-Trace: news2.rdc2.tx.home.com 1004068840 24.254.173.165 (Thu, 25 Oct 2001 21:00:40 PDT) NNTP-Posting-Date: Thu, 25 Oct 2001 21:00:40 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:15209 Date: 2001-10-26T04:00:40+00:00 List-Id: "Adrian Hoe" wrote in message news:9ff447f2.0110100005.2503bb00@posting.google.com... > Hello, > > 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; > 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. > > 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. As you indicated in another post, neither pragma pack nor a rep clause gives you what you want. This is because neither of these will violate the alignment rules for a given type. Unless you can use Streams_Io to read and write (and you don't have to worry about what the data looks like otherwise), you will have to do something ugly, like: 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; L0 : Character; L1 : Character; L2 : Character; L3 : Character; End_Byte : Character := Latin_1.ETX; LRC : Character; end record; subtype Str4 is String(1..4); function Convert is new Unchecked_Conversion (Source => Str4, Target => Interfaces.C.Long); Log_Num_Str : Str4 := Rx_Header_Data.L0 & Rx_Header_Data.L1 & Rx_Header_Data.L2 & Rx_Header_Data.L3; Log_Num : Interfaces.C.Long := Convert(Log_Num_Str); Markku