comp.lang.ada
 help / color / mirror / Atom feed
From: "Norman H. Cohen" <ncohen@watson.ibm.com>
Subject: Re: Help
Date: 1996/11/18
Date: 1996-11-18T00:00:00+00:00	[thread overview]
Message-ID: <329095B3.6635@watson.ibm.com> (raw)
In-Reply-To: 328C2BF5.1348@informatik.tu-muenchen.de


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




  parent reply	other threads:[~1996-11-18  0:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-15  0:00 Help Alexander B. Schmidt
1996-11-15  0:00 ` Help Michael Paus
1996-11-18  0:00 ` Norman H. Cohen [this message]
1996-11-19  0:00 ` Help Matthew Heaney
  -- strict thread matches above, loose matches on Subject: below --
2001-09-19 19:51 help mop
2001-09-20  8:41 ` help John McCabe
1998-12-07  0:00 help Salvador
1998-12-07  0:00 ` help dennison
1997-02-27  0:00 Help Desperate
1997-03-04  0:00 ` Help Jim Dorman
1994-10-19 16:26 HELP CONDIC
1994-10-14  3:33 HELP Chiu Bo (Hung Chiu Hung)
1994-10-14 13:21 ` HELP Robert Dewar
1994-10-15 14:56   ` HELP Bob Duff
1994-10-18 16:31     ` HELP Robert Dewar
1994-10-16  5:11   ` HELP Chiu Bo (Hung Chiu Hung)
1994-10-14 19:36 ` HELP riehler
1994-10-14 19:36 ` HELP Richard Riehle
1994-10-19  3:10 ` HELP Michael M. Bishop
1993-03-12 22:28 Help Basavaraj B Patil
1990-08-01 18:19 Help Kenneth Anderson
replies disabled

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