Right.

A number of times it's been emphasized that a String has a fixed length. What happens if you really want to vary a string's length?

One solution is to create a long string, long enough to hold the maximum number of characters in a String, and then use another variable to store the number of characters currently used in the String. This may be appropriate when actual string sizes are (on the average) close to the maximum string size and when maximum string sizes can be predetermined. That idea is the basis for the Bounded_String type we mentioned earlier.

Another solution is to create an "access (pointer) to string" variable (we haven't discussed "access" types yet, but Ada provides them). Such a variable would be very similar to C and C++'s char * type. Unlike C and C++, Ada provides a number of built-in protections for "access to String" types. Still, varying-length Strings occur often enough that Ada 95 provides a predefined type, Unbounded_String, that does some additional housekeeping for us. Unbounded_String is usually implemented using String in some way, but it does a number of things automatically for us. Thus, we will talk about Unbounded_String next, and discuss "access to String" later.

You may go to the next section.

You may also:

PREVIOUS Go back to the question

OUTLINE  Go up to the outline of lesson 8

David A. Wheeler (dwheeler@dwheeler.com)

The master copy of this file is at "http://www.adahome.com/Tutorials/Lovelace/s8s4r1.htm".