comp.lang.ada
 help / color / mirror / Atom feed
From: tonyg <tonythegair@gmail.com>
Subject: Re: GNAT.Serial_Communications
Date: Sat, 16 Apr 2011 03:21:56 -0700 (PDT)
Date: 2011-04-16T03:21:56-07:00	[thread overview]
Message-ID: <ce708bed-16e5-41a6-9144-41defb06d368@dn9g2000vbb.googlegroups.com> (raw)
In-Reply-To: ioa35s$an7$1@tornado.tornevall.net

On Apr 15, 7:01 pm, Jeffrey Carter
<spam.jrcarter....@spam.not.acm.org> wrote:
> On 04/15/2011 09:32 AM, tonyg wrote:
>
> >        for count in
> > 1..Ada.Streams.Stream_Element_Offset(The_String'Length) loop
> >           Return_Value(count) :=
> > character'pos(The_String(Integer(count)));
>
> You assume that The_String'First = 1, which will not be the case if you pass a
> slice with a different lower bound. However, that will cause Constraint_Error
> (unless you have turned off this check), which does not seem to be the problem.
>
> >        Return 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
>     subtype String3 is String (1 .. 3);
>
>     From : constant String3 := "abc";
>
>     subtype Stream3 is Ada.Streams.Stream_Element_Array (1 .. From'Length);
>
>     function To_Stream is new Ada.Unchecked_Conversion (Source => String3,
> Target => Stream3);
>
>     To : Stream3;
> begin -- Stream_Convert
>     To := To_Stream (From);
>
>     Output : for I in To'range loop
>        Ada.Text_IO.Put (Item => To (I)'Img);
>     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.



  reply	other threads:[~2011-04-16 10:21 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-11 10:26 GNAT.Serial_Communications tonyg
2011-04-11 11:11 ` GNAT.Serial_Communications Brian Drummond
2011-04-13  7:49   ` GNAT.Serial_Communications tonyg
2011-04-13 14:12     ` GNAT.Serial_Communications Alex Mentis
2011-04-13 21:12       ` GNAT.Serial_Communications tonyg
2011-04-14 13:15         ` GNAT.Serial_Communications Alex Mentis
2011-04-14 17:52         ` GNAT.Serial_Communications Chris Moore
2011-04-15 13:58           ` GNAT.Serial_Communications tonyg
2011-04-15 16:32             ` GNAT.Serial_Communications tonyg
2011-04-15 17:12               ` GNAT.Serial_Communications Simon Clubley
2011-04-15 17:32                 ` GNAT.Serial_Communications tonyg
2011-04-15 18:49                   ` GNAT.Serial_Communications Simon Clubley
2011-04-16  0:07                     ` GNAT.Serial_Communications tonyg
2011-04-16  8:29                       ` GNAT.Serial_Communications Simon Clubley
2011-04-16 10:19                         ` GNAT.Serial_Communications tonyg
2011-04-16 10:33                           ` GNAT.Serial_Communications tonyg
2011-04-16 11:15                             ` GNAT.Serial_Communications Brian Drummond
2011-04-16 12:03                               ` GNAT.Serial_Communications tonyg
2011-04-16 15:12                                 ` GNAT.Serial_Communications Simon Clubley
2011-04-18 20:31                                   ` GNAT.Serial_Communications tonyg
2011-04-18 20:43                                   ` GNAT.Serial_Communications tonyg
2011-04-19 11:46                                     ` GNAT.Serial_Communications tonyg
2011-04-19 12:09                                       ` GNAT.Serial_Communications Ludovic Brenta
2011-04-19 13:53                                         ` GNAT.Serial_Communications tonyg
2011-04-19 19:06                                           ` GNAT.Serial_Communications Ludovic Brenta
2011-04-19 19:57                                         ` GNAT.Serial_Communications Alex Mentis
2011-04-20 11:37                                           ` GNAT.Serial_Communications tonyg
2011-04-20 14:22                                             ` GNAT.Serial_Communications Alex Mentis
2011-04-21  9:00                                               ` GNAT.Serial_Communications tonyg
2011-04-21 13:28                                                 ` GNAT.Serial_Communications Alex Mentis
2011-04-22 13:55                                                 ` GNAT.Serial_Communications Alex Mentis
2011-04-22 15:52                                                   ` GNAT.Serial_Communications Brian Drummond
2011-04-19 13:32                                       ` GNAT.Serial_Communications Simon Clubley
2011-04-19 16:59                                         ` GNAT.Serial_Communications Simon Clubley
2011-04-20 10:17                                         ` GNAT.Serial_Communications Brian Drummond
2011-04-20 20:46                                         ` GNAT.Serial_Communications Brian Drummond
2011-04-21  4:28                                           ` GNAT.Serial_Communications Simon Wright
2011-04-21  9:12                                             ` GNAT.Serial_Communications tonyg
2011-04-21 10:14                                               ` GNAT.Serial_Communications tonyg
2011-04-22 15:54                                             ` GNAT.Serial_Communications Brian Drummond
2011-04-22 16:14                                               ` GNAT.Serial_Communications Simon Wright
2011-04-21 11:56                                           ` GNAT.Serial_Communications Simon Clubley
2011-04-15 18:01               ` GNAT.Serial_Communications Jeffrey Carter
2011-04-16 10:21                 ` tonyg [this message]
2016-12-01 19:58 ` GNAT.Serial_Communications mario.blunk.gplus
2017-03-20 15:20   ` GNAT.Serial_Communications Jacob Sparre Andersen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox