From: "Marc A. Criley" <mcqada@earthlink.net>
Subject: Re: How to convert record?
Date: Thu, 25 Oct 2001 12:48:42 GMT
Date: 2001-10-25T12:48:42+00:00 [thread overview]
Message-ID: <3BD7FE89.53BF8436@earthlink.net> (raw)
In-Reply-To: 80d2e34.0110250340.155ae0b7@posting.google.com
Joseph Kwan wrote:
>
> john.mccabe@emrad.com.nospam (John McCabe) wrote in message news:<3bd402f9.8783319@news.demon.co.uk>...
> > On 21 Oct 2001 02:56:25 -0700, joseph_kwan@greenlime.com (Joseph Kwan)
> > wrote:
> >
> > >I want to send a command buffer to serial port using florist's POSIX
> > >interface but I have encountered problems in converting record to
> > >POSIX.IO.IO_Buffer or Ada.Streams.Stream_Element_Array. How can I
> > >overcome this problem?
> >
> > Without looking at the Reference Manual, I would initially suggest
> > looking at Ada.Unchecked_Conversion to do the job.
>
> I thought that would work too but theoretically,
> Ada.Unchecked_Conversion will not work in converting record to
> POSIX.IO.IO_Buffer which is a string of characters (See spec in
> florist's implementation).
>
> Anyhow I tried to do Unchecked_Conversion and gnat gave me error
> message:
>
> "unchecked conversion to unconstrained array not allowed".
>
> What should I do?
Caveat: I don't have POSIX stuff here, so I'm making some assumptions.
1) How many storage units (i.e., bytes) do objects of that record type
require? Use 'Size on a _variable_ of that type, not the type itself,
and divide by System.Storage_Unit (i.e., 8).
2) How many elements of IO_Buffer are required to occupy that same
number of storage units? (If IO_Buffer is an array of Character, then
it is almost certainly the same as the number of storage units from
above.)
3) Define a subtype of IO_Buffer with an index constraint containing
that number of elements.
4) Instantiate Unchecked_Conversion with your record type and that
IO_Buffer subtype.
5) Convert.
Marc A. Criley
Senior Staff Engineer
Quadrus Corporation
www.quadruscorp.com
next prev parent reply other threads:[~2001-10-25 12:48 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-10-21 9:56 How to convert record? Joseph Kwan
2001-10-22 11:30 ` John McCabe
2001-10-25 11:40 ` Joseph Kwan
2001-10-25 12:38 ` sk
2001-10-25 17:12 ` Jeffrey L. Susanj
2001-10-25 12:48 ` David C. Hoos
2001-10-29 1:42 ` Joseph Kwan
2001-10-29 13:35 ` Marc A. Criley
2001-10-25 12:48 ` Marc A. Criley [this message]
2001-10-25 12:54 ` sk
2001-10-25 15:41 ` Ted Dennison
2001-10-26 3:21 ` Smark
2001-10-26 5:45 ` James Rogers
2001-10-26 17:46 ` Smark
2001-10-26 14:30 ` Ted Dennison
2001-10-26 17:42 ` Smark
2001-10-26 20:02 ` Ted Dennison
2001-10-26 23:10 ` Jeffrey Carter
-- strict thread matches above, loose matches on Subject: below --
2001-10-29 18:16 Beard, Frank
2001-10-30 1:17 ` Adrian Hoe
2001-10-30 19:05 Beard, Frank
2001-10-31 4:10 ` Adrian Hoe
2001-10-31 19:40 Beard, Frank
2001-11-01 2:13 ` Adrian Hoe
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox