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,79db4ff72bff9422 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-10-25 05:48:42 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!netnews.com!xfer02.netnews.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3BD7FE89.53BF8436@earthlink.net> From: "Marc A. Criley" Organization: Quadrus Corporation X-Mailer: Mozilla 4.73 [en] (X11; U; Linux 2.2.14-5.0 i686) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How to convert record? References: <80d2e34.0110210156.7918cd3d@posting.google.com> <3bd402f9.8783319@news.demon.co.uk> <80d2e34.0110250340.155ae0b7@posting.google.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Thu, 25 Oct 2001 12:48:42 GMT NNTP-Posting-Host: 158.252.123.82 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1004014122 158.252.123.82 (Thu, 25 Oct 2001 05:48:42 PDT) NNTP-Posting-Date: Thu, 25 Oct 2001 05:48:42 PDT X-Received-Date: Thu, 25 Oct 2001 05:44:52 PDT (newsmaster1.prod.itd.earthlink.net) Xref: archiver1.google.com comp.lang.ada:15181 Date: 2001-10-25T12:48:42+00:00 List-Id: 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