From: Warren <ve3wwg@gmail.com>
Subject: type String_Type array(Integer range <>) of Character;
Date: Fri, 16 Apr 2010 19:52:46 +0000 (UTC)
Date: 2010-04-16T19:52:46+00:00 [thread overview]
Message-ID: <Xns9D5CA189A3710WarrensBlatherings@188.40.43.245> (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
next reply other threads:[~2010-04-16 19:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-16 19:52 Warren [this message]
2010-04-16 21:09 ` type String_Type array(Integer range <>) of Character; 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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox