comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <mheaney@on2.com>
Subject: Re: Bounds of Slice's return value
Date: Mon, 21 Jan 2002 15:19:27 -0500
Date: 2002-01-21T15:19:27-05:00	[thread overview]
Message-ID: <u4otlji46nm3db@corp.supernews.com> (raw)
In-Reply-To: 87bsfrcksf.fsf@chiark.greenend.org.uk


"Matthew Woodcraft" <mattheww@chiark.greenend.org.uk> wrote in message
news:87bsfrcksf.fsf@chiark.greenend.org.uk...
> In particular, if I run the following program, should I always get '1',
> or is an implementation allowed to choose a different value?
>
> procedure Slice_Return_Value is
>    U : Unbounded_String := To_Unbounded_String ("hello");
>    S : String := Slice (U, 2, 3);
> begin
>    Put_Line (Integer'Image (S'first));
> end Slice_Return_Value;

You can fix this to specify the index constraint you desire, using a subtype
constraint:

declare
   F : constant Positive := 2;
   L : constant Positive := 3;
   S : constant String (1 .. L - F + 1) := Slice (U, F, L);
begin

or

declare
   F : constant Positive := 2;
   L : constant Positive := 3;
   S : constant String (F .. L) := Slice (U, F, L);
begin

Of course, this declares a constrained string object (no dope vector is
generated), so this is not strictly comparable to your original example.
You could fix that by using an explicit subtype:

declare
   F : constant Positive := 2;
   L : constant Positive := 3;
   subtype T is String (1 .. L - F + 1);
   S : constant String := T(Slice (U, F, L));
begin

or

declare
   F : constant Positive := 2;
   L : constant Positive := 3;
   subtype T is String (F .. L);
   S : constant String := T(Slice (U, F, L));
begin






      parent reply	other threads:[~2002-01-21 20:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-18 23:16 Bounds of Slice's return value Matthew Woodcraft
2002-01-19  1:24 ` Jeffrey Carter
2002-01-19 10:45   ` Matthew Woodcraft
2002-01-19 14:32     ` Robert A Duff
2002-01-19 17:19       ` Matthew Woodcraft
2002-01-21 20:19 ` Matthew Heaney [this message]
replies disabled

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