comp.lang.ada
 help / color / mirror / Atom feed
From: "James S. Rogers" <jimmaureenrogers@worldnet.att.net>
Subject: Re: [Spark] Converting Arrays
Date: Mon, 10 Mar 2003 20:03:09 GMT
Date: 2003-03-10T20:03:09+00:00	[thread overview]
Message-ID: <1c6ba.19009$Oz1.770240@bgtnsc05-news.ops.worldnet.att.net> (raw)
In-Reply-To: slrnb6phge.1gd.lutz@taranis.iks-jena.de

"Lutz Donnerhacke" <lutz@iks-jena.de> wrote in message
news:slrnb6phge.1gd.lutz@taranis.iks-jena.de...
> I run into a difficult problem (for me):
> $ cat test.ada <<END
> package test is
>    type Fullpath is array(Positive range <>) of Character;
>    procedure To_Fullpath (s : String; path : out Fullpath);
>    --# derives path from s;
> end test;
>
> package body test is
>    procedure To_Fullpath (s : String; path : out Fullpath) is
>    begin
>       path := Fullpath'(others => ASCII.NUL);
>       for i in Positive range 1 .. s'Length loop
>         path (path'First + i) := s (s'First + i);
>       end loop;
>    end To_Fullpath;
> end test;

change the initialization of "path" as follows:

path := (others => ASCII.NUL);

Note that another problem looms in your code.
The "for" loop will attempt to access one element
beyond the end of string "s".
It appears that you are trying to copy s into path
while skipping the first element of s. This can be done
more directly and correctly with array slices:

if s'Length <= path'Length then
   path(path'First..(path'First + s'Length - 1)) := s((s'First +
1)..s'Last);
end if;

You will need to decide how to handle the case when
path is shorter than s.

Jim Rogers





  reply	other threads:[~2003-03-10 20:03 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-10 17:06 [Spark] Converting Arrays Lutz Donnerhacke
2003-03-10 20:03 ` James S. Rogers [this message]
2003-03-10 22:33   ` Lutz Donnerhacke
2003-03-11 10:14 ` Rod Chapman
2003-03-11 10:51   ` Lutz Donnerhacke
2003-03-11 10:52   ` Lutz Donnerhacke
2003-03-11 20:46     ` JP Thornley
2003-03-12  8:43       ` Phil Thornley
2003-03-12 11:57         ` Lutz Donnerhacke
2003-03-12 18:46           ` JP Thornley
2003-03-13 10:14             ` Lutz Donnerhacke
2003-03-12  9:43     ` Rod Chapman
2003-03-12 10:15       ` Lutz Donnerhacke
  -- strict thread matches above, loose matches on Subject: below --
2003-03-13  5:55 Grein, Christoph
2003-03-13  9:47 ` Peter Amey
2003-03-13 10:15   ` Lutz Donnerhacke
2003-03-21 15:05     ` Peter Amey
2003-03-21 15:17       ` Lutz Donnerhacke
replies disabled

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