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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,754e583fcabdfad2 X-Google-Attributes: gid103376,public From: "Norman H. Cohen" Subject: Re: Help Date: 1996/11/18 Message-ID: <329095B3.6635@watson.ibm.com>#1/1 X-Deja-AN: 197236305 references: <328C2BF5.1348@informatik.tu-muenchen.de> content-type: text/plain; charset=us-ascii organization: IBM Thomas J. Watson Research Center mime-version: 1.0 reply-to: ncohen@watson.ibm.com newsgroups: comp.lang.ada x-mailer: Mozilla 3.0 (Win95; I) Date: 1996-11-18T00:00:00+00:00 List-Id: Alexander B. Schmidt wrote: > does anybody know how to declare a string of variable length in Ada > 83? Declaring a variable of type String like > str: STRING(1..20); > and assigning a string like > str := "a String" > results in a constraint error if the length of the string is not equal > to 20. > Is it possible to declare strings with a maximum length which accept > the assignment of shorter strings too? Ada 95 directly supports the notion of a variable length string, but Ada 83 does not. In either version of Ada, an object of type String (such as str in your example) has bounds that are determined once and for all at the time the object is created. The usual Ada-83 solution is to use an access type pointing to objects of type String. An object belonging to the access type can point to different-length string objects at different times: type String_Pointer_Type is access String; Str_Ptr: String_Pointer_Type; ... Str_Ptr := new String'("Short string"); Str_Ptr := new String'("A longer string"); -- Norman H. Cohen mailto:ncohen@watson.ibm.com http://www.research.ibm.com/people/n/ncohen