From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3a2f76c3562b7f58,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!feeder.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Warren Newsgroups: comp.lang.ada Subject: type String_Type array(Integer range <>) of Character; Date: Fri, 16 Apr 2010 19:52:46 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: Injection-Date: Fri, 16 Apr 2010 19:52:46 +0000 (UTC) Injection-Info: feeder.eternal-september.org; posting-host="9f8M0iN5t54V+4DF/iqO8g"; logging-data="16227"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+kBth3xJ4ENWauDv7nMVeokdeAqGlP8sQ=" User-Agent: Xnews/5.04.25 X-Face: &6@]C2>ZS=NM|HE-^zWuryN#Z/2_.s9E|G&~DRi|sav9{E}XQJb*\_>=a5"q]\%A;5}LKP][1mA{gZ,Q!j Cancel-Lock: sha1:glm0HozCCEQcUnQpl6jXDmkv9Uk= Xref: g2news2.google.com comp.lang.ada:10994 Date: 2010-04-16T19:52:46+00:00 List-Id: 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