comp.lang.ada
 help / color / mirror / Atom feed
* type String_Type array(Integer range <>) of Character;
@ 2010-04-16 19:52 Warren
  2010-04-16 21:09 ` stefan-lucks
  0 siblings, 1 reply; 6+ messages in thread
From: Warren @ 2010-04-16 19:52 UTC (permalink / raw)


I am looking for some sound Ada ('05) advice on
a design issue, concerning strings. 

In my basic interpreter, I permit the end user 
to choose the array subscript ranges just like
in Ada. 

But this includes strings, whereas in Ada one 
generally just uses the String type, with 
its positive subscript values.

I would find it convenient in the interpreter to
use a string type with an Integer range for Basic
string variables instead:

type String_Type is 
    array(Integer range <>) of Character;

This allows subscripts to range negative to
positive. The reason for this approach is that
any dynamically allocated string would also 
carry this "bounds" info with it, saving me 
from having to manage it separately.

However, I'll need to convert them back to 
normal Ada Strings in order to manipulate 
and print them etc.

The following snippet highlights the challenge:

with Ada.Text_IO; use Ada.Text_IO;

procedure M is

  type String_Type is array(Integer range <>) of Character;

  S : String_Type := "Abc.";
  T : String(1..4);
begin

  T := String(S);
  Put_Line(T);

end M;

$ gnatmake -Wall m.adb
gcc -c -Wall m.adb
m.adb:11:17: warning: value out of range of type "Standard.String"
m.adb:11:17: warning: "Constraint_Error" will be raised at run time
gnatbind -x m.ali
gnatlink m.ali

Is there a simple way to "slide" my String_Type
into a normal Ada String array?  

Or must I do this in a custom function for the
purpose, character by character?  

Warren



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

end of thread, other threads:[~2010-04-19 15:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-16 19:52 type String_Type array(Integer range <>) of Character; Warren
2010-04-16 21:09 ` stefan-lucks
2010-04-16 20:29   ` J-P. Rosen
2010-04-16 20:53     ` Charmed Snark
2010-04-16 20:56     ` Adam Beneschan
2010-04-19 15:27       ` Warren

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