From: Jeffrey Carter <jeffrey.carter@boeing.com>
Subject: Re: records containing variable length arrays [long]
Date: Fri, 8 Jun 2001 22:28:34 GMT
Date: 2001-06-08T22:28:34+00:00 [thread overview]
Message-ID: <3B215192.D1A698E3@boeing.com> (raw)
In-Reply-To: 3B210083.BD164849@boeing.com
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
next prev parent reply other threads:[~2001-06-08 22:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-06 19:59 records containing variable length arrays [long] Mats Karlssohn
2001-06-06 23:06 ` Jeffrey Carter
2001-06-07 11:44 ` Mats Karlssohn
2001-06-08 2:10 ` Jeffrey Carter
2001-06-07 21:38 ` Stephen Leake
2001-06-08 12:32 ` Mats Karlssohn
2001-06-08 16:42 ` Jeffrey Carter
2001-06-08 22:28 ` Jeffrey Carter [this message]
2001-06-19 11:43 ` Mats Karlssohn
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox