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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,cc65ab136f46904d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!dn9g2000vbb.googlegroups.com!not-for-mail From: tonyg Newsgroups: comp.lang.ada Subject: Re: GNAT.Serial_Communications Date: Sat, 16 Apr 2011 03:21:56 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <9af0087d-9637-40d9-8c30-2e06c2d1e4f4@o26g2000vby.googlegroups.com> NNTP-Posting-Host: 82.46.232.121 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1302949316 19109 127.0.0.1 (16 Apr 2011 10:21:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 16 Apr 2011 10:21:56 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: dn9g2000vbb.googlegroups.com; posting-host=82.46.232.121; posting-account=28F2IwkAAACL1Z5nRC-dE7zuvWdbWC7P User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.9.2.16) Gecko/20110323 Ubuntu/10.04 (lucid) Firefox/3.6.16,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:19783 Date: 2011-04-16T03:21:56-07:00 List-Id: On Apr 15, 7:01=A0pm, Jeffrey Carter wrote: > On 04/15/2011 09:32 AM, tonyg wrote: > > > =A0 =A0 =A0 =A0for count in > > 1..Ada.Streams.Stream_Element_Offset(The_String'Length) loop > > =A0 =A0 =A0 =A0 =A0 Return_Value(count) :=3D > > character'pos(The_String(Integer(count))); > > You assume that The_String'First =3D 1, which will not be the case if you= pass a > slice with a different lower bound. However, that will cause Constraint_E= rror > (unless you have turned off this check), which does not seem to be the pr= oblem. > > > =A0 =A0 =A0 =A0Return Return_Value(1..The_String'Length); > > I see no reason for the slice. > > You should be able to replace the body of String_To_Stream with a simple > Unchecked_Conversion: > > with Ada.Streams; > with Ada.Text_IO; > with Ada.Unchecked_Conversion; > > procedure Stream_Convert is > =A0 =A0 subtype String3 is String (1 .. 3); > > =A0 =A0 From : constant String3 :=3D "abc"; > > =A0 =A0 subtype Stream3 is Ada.Streams.Stream_Element_Array (1 .. From'Le= ngth); > > =A0 =A0 function To_Stream is new Ada.Unchecked_Conversion (Source =3D> S= tring3, > Target =3D> Stream3); > > =A0 =A0 To : Stream3; > begin -- Stream_Convert > =A0 =A0 To :=3D To_Stream (From); > > =A0 =A0 Output : for I in To'range loop > =A0 =A0 =A0 =A0Ada.Text_IO.Put (Item =3D> To (I)'Img); > =A0 =A0 end loop Output; > end Stream_Convert; > > -- > Jeff Carter > "Unix and C are the ultimate computer viruses." > Richard Gabriel > 99 I did that because I got a bit paranoid with the way ada handles strings after finding out something new in the way its handles them. I used to think that a slice's indexes changed when it went through a procedure or functions paramaters but came unstuck by it. Thanks for the code, I'll give it a try once I get this naughty serial port sorted.