comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jeffrey.carter@boeing.com>
Subject: Re: records containing variable length arrays [long]
Date: Fri, 8 Jun 2001 16:42:43 GMT
Date: 2001-06-08T16:42:43+00:00	[thread overview]
Message-ID: <3B210083.BD164849@boeing.com> (raw)
In-Reply-To: 3B20C5F7.94DC72A1@mida.se

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);

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



  reply	other threads:[~2001-06-08 16:42 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 [this message]
2001-06-08 22:28     ` Jeffrey Carter
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