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,dcfafdc50abb8ce4 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-08 15:44:12 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!uunet!dca.uu.net!ash.uu.net!xyzzy!nntp From: Jeffrey Carter Subject: Re: records containing variable length arrays [long] X-Nntp-Posting-Host: e246420.msc.az.boeing.com Content-Type: text/plain; charset=us-ascii Message-ID: <3B215192.D1A698E3@boeing.com> Sender: nntp@news.boeing.com (Boeing NNTP News Access) Content-Transfer-Encoding: 7bit Organization: The Boeing Company X-Accept-Language: en References: <3B1E8BB9.42BF95D2@mida.se> <3B20C5F7.94DC72A1@mida.se> <3B210083.BD164849@boeing.com> Mime-Version: 1.0 Date: Fri, 8 Jun 2001 22:28:34 GMT X-Mailer: Mozilla 4.5 [en]C-CCK-MCD Boeing Kit (WinNT; U) Xref: archiver1.google.com comp.lang.ada:8460 Date: 2001-06-08T22:28:34+00:00 List-Id: Jeffrey Carter wrote: > > Mats Karlssohn wrote: > > > > I ended up declaring the record in the way that was discussed earlier. > > Then I declare an access type to the record and use an instance of > > System.Address_To_Access_Conversions to convert the C pointer to an > > Ada pointer. I'll probably wrap another layer around the buffer > > manager and let that glue perform the address to access conversion. > > You can probably avoid the conversion of the pointer. Given > > type Message (...) is record ...; > for Message use record ...; > > and something like > > void get (buffer* p, int* len); This is probably wrong, but my C is bad, so I tend to get things wrong. What is needed here is the equivalent of Ada's "P : out Ptr_To_Byte", which on second look is probably byte** p > > you can define > > type Message_Ptr is access all Message; > pragma Convention (C, Message_Ptr); > > procedure Get (Ptr : out Message_Ptr; Length : out Interfaces.C.Int); > pragma Import (C, Get, "get"); > > and use the access value you get from Get directly. > > > Given this declaration and representation: > > > > type Message(Response_Length : Byte; Output_Length : Byte) is > > record > > Magic : Word; > > Operation : Word; > > Status : Word; > > Response_Data : Buffer(1..Response_Length); > > Output_Data : Buffer(1..Output_Length); > > CRC : Word; > > end record; > > > > for Message use > > record > > Magic at 0 range 0..15; > > Operation at 2 range 0..15; > > Status at 4 range 0..15; > > Response_Length at 6 range 0.. 7; > > Output_Length at 7 range 0.. 7; > > end record; > > > > pragma Pack(Message); > > > > Is there a way to explicitly put at least the CRC element into the > > representation clause ? My experiments haven't gotten me anywhere > > on this part. > > Only if it comes before the variable-length part of the record. The > values used in a record representation clause have to be static, which > means known at compile time. > > -- > Jeffrey Carter -- Jeffrey Carter