comp.lang.ada
 help / color / mirror / Atom feed
* Lower bound of result of Ada.Strings.Unbounded.Slice
@ 2000-11-21  0:00 Jeff Carter
  2000-11-22  4:59 ` Robert Dewar
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Carter @ 2000-11-21  0:00 UTC (permalink / raw)


Consider the following program:

with Ada.Strings.Unbounded;
with Ada.Text_Io;

use Ada.Strings.Unbounded;
use Ada.Text_Io;
procedure Slice_Test is
   Line : constant String := "This is a nice long line.";

   U_Line : constant Unbounded_String := To_Unbounded_String (Line);
begin -- Slice_Test
   Put_Line ("Slice (U_Line, 3, 7)'First =>" &
             Integer'Image (Slice (U_Line, 3, 7)'First) &
             "; Slice (U_Line, 3, 7)'Last =>" &
             Integer'Image (Slice (U_Line, 3, 7)'Last) );
end Slice_Test;

Compiler A has 1 and 5 in its output, while compiler B has 3 and 7.

As far as I can tell from the ARM, both results are acceptable. So are
22 and 26.

This makes it difficult to write portable code that uses an index in the
result of Slice to access a position in the whole string. Consistency
across compilers here would be a Good Thing, IMHO. The value of the Low
parameter to Slice would be the better lower bound, I think, since it is
what you get with type String.

Is this something I should submit as a potential AI?

-- 
Jeff Carter
"Nobody expects the Spanish Inquisition!"
Monty Python's Flying Circus




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2000-11-23  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-21  0:00 Lower bound of result of Ada.Strings.Unbounded.Slice Jeff Carter
2000-11-22  4:59 ` Robert Dewar
2000-11-22  0:00   ` Jeff Carter
2000-11-22  0:00     ` Randy Brukardt
2000-11-23  0:00       ` Jeff Carter

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