comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: records containing variable length arrays [long]
Date: Fri, 08 Jun 2001 02:10:08 GMT
Date: 2001-06-08T02:10:08+00:00	[thread overview]
Message-ID: <3B2033F5.366D250A@acm.org> (raw)
In-Reply-To: 3B1F6939.88D49233@mida.se

Mats Karlssohn wrote:
> 
> Jeffrey Carter wrote:
> >
> > Mats Karlssohn wrote:
> 
> > >    -- the other big problem is to get the correct representation
> > >    for Message use
> > >       record
> %<
> > >           Status          at 4 range 0..15;
> > >           Response_Length at 4 range 0.. 7;
> 
> This is a typo... "Response_Length at 5 range 0..7;" is the correct
> representation statement, this also means that all the following
> components move up one byte.

Good. That makes life easier for you.

> 
> %<
> > However, you have additional problems, such as overlaying your lengths,
> > which would be your discriminants, with Status. I presume that you
> > receive your message as a simple Buffer. In that case you might be able
> > to work something along these lines
> 
> Yes, I receive a C pointer (converted to System.Address) and an integer
> Length from a buffer manager for the shared memory where thit beast
> lives. I forgot to mention that I really only neet to read this data
> structure, I will NOT need to assign to it.

In that case you can access it simply. We'll call what you get from C
Data_Address and Data_Length. Then you can say

Raw_Data : constant Buffer (1 .. Data_Length);
-- or (7 .. Data_Length + 6), if you prefer
pragma Import (Ada, Raw_Data); -- Prevent any initialization of Raw_Data
for Raw_Data'Address use Data_Address;

You can then Translate this to an appropriately constrained record type.
Since you do not need to modify it, you can make it constant, which
should avoid copying the data.

If you want to live dangerously, you can avoid the buffer representation
and simply apply the address clause to the record object.

-- 
Jeff Carter
"Perfidious English mouse-dropping hoarders."
Monty Python & the Holy Grail



  reply	other threads:[~2001-06-08  2:10 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 [this message]
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
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