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,LOTS_OF_MONEY 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-26 10:51:33 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newshub2.home.com!news.home.com!news2.rdc2.tx.home.com.POSTED!not-for-mail From: "Smark" Newsgroups: comp.lang.ada References: <8b7C7.72629$gT6.36974049@news1.rdc1.sfba.home.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 17:51:32 GMT NNTP-Posting-Host: 24.254.173.165 X-Complaints-To: abuse@home.net X-Trace: news2.rdc2.tx.home.com 1004118692 24.254.173.165 (Fri, 26 Oct 2001 10:51:32 PDT) NNTP-Posting-Date: Fri, 26 Oct 2001 10:51:32 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:15270 Date: 2001-10-26T17:51:32+00:00 List-Id: wrote in message news:8b7C7.72629$gT6.36974049@news1.rdc1.sfba.home.com... > >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. > I seem to have missed the previous post, so I don't know what the > problem is. The following code works just fine - isn't it what you want? > 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; > for Rx_Header_Data 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; > Pad_Byte_2 at 4 range 0 .. 7; > Log_Num at 5 range 0 .. 31; > End_Byte at 9 range 0 .. 7; > LRC at 10 range 0 .. 7; > end record; > for Rx_Header_Data'size use 8*11; The problem was that this rep clause will not work, because Log_Num must be aligned to a 4-byte boundary. Some compilers will silently ignore your rep clause, I believe GNAT will tell you it can't do it. > > subtype str is String(1 .. 11); > function to_str is new ada.unchecked_conversion(source=>Rx_Header_Data, > target=>str); > a : Rx_Header_Data; > b : str; > begin > b := to_str(a); > ----------- > (Of course it's really ugly to use String where Storage_Element is clearly > what is meant.) Agreed. Markku